I already have a class to do a shape program in window form application , but I don't know how to write a code in Form1.cs to show the area of shapes and draw after choosing the combobox - circle , triangle, square. when click the 'Area button' and draw the shape when click 'draw' , and how to enable and disable textbox of typing number when in use , ie. Circle needs to fill radius only , then change the combobox to triangle needs to fill base and height.
The Shape Class is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
namespace Class_Shape
{
class Shape
{
public string[] GetShape()
{
string []s = {"circle","triangle","square"};
return s;
}
public double CircleArea(double radius)
{
return Math.PI * radius * radius;
}
public double RectangleArea(double width, double height)
{
return width * height;
}
public double TangleArea(double width,double height)
{
return 0.5 * width * height;
}
public void DrawCircle(double r,Form1 f)
{
Pen big = new Pen(Brushes.Red ,5);
f.Refresh ();
f.CreateGraphics().DrawEllipse(big, (float) 110,(float) 160,(float) r,(float) r);
f.CreateGraphics().FillEllipse(Brushes.YellowGreen , (float)110, (float)160, (float)r, (float)r);
}
public void DrawRect(double w,double h, Form1 f)
{
Pen big = new Pen(Brushes.Red, 5);
f.Refresh();
f.CreateGraphics().DrawRectangle (big, (float)110, (float)160, (float)w, (float)h);
f.CreateGraphics().FillRectangle (Brushes.YellowGreen, (float)110, (float)160, (float)w, (float)h);
}
public void DrawTang(double w, double h, Form1 f)
{
Pen big = new Pen(Brushes.Red, 5);
Point [] p = {new Point(120, 160),new Point(120,160+(int)h), new Point(120+(int)w,160+(int)h) } ;
f.Refresh();
f.CreateGraphics().DrawPolygon(big, p);
f.CreateGraphics().FillPolygon(Brushes.YellowGreen , p);
}
}
}