//the class PaintEventArgs provides data for the object event Paint private void panelDrawing_Paint(object sender, PaintEventArgs e) { // Fill before painting to have a lighter border // Rectangle if (this.radioButtonRectangle.Checked == true && myRectangle != null) { if (fill) { myRectangle.Fill(e); } myRectangle.Draw(e); this.textBoxDisplay.Text = myRectangle.ToString(); } // Square if (this.radioButtonSquare.Checked == true && mySquare != null) { if (fill) { mySquare.Fill(e); } mySquare.Draw(e); this.textBoxDisplay.Text = mySquare.ToString(); } // Circle if (this.radioButtonCircle.Checked == true && myCircle != null) { if (fill) { myCircle.Fill(e); } myCircle.Draw(e); this.textBoxDisplay.Text = myCircle.ToString(); } // Ellipse if (this.radioButtonEllipse.Checked == true && myEllipse != null) { if (fill) { myEllipse.Fill(e); } myEllipse.Draw(e); this.textBoxDisplay.Text = myEllipse.ToString(); } }
static void Main(string[] args) { Point centreRect = new Point(1, 1); Point centreSquare = new Point(0, 0); Rectangle rect = new Rectangle(3, 5, centreRect); Square square = new Square(2, centreSquare); Ellipse ellipse = new Ellipse(2, 1, centreSquare); Console.WriteLine(rect.ToString()); Console.WriteLine(rect.GetArea() + " " + rect.GetPerimeter()); Console.WriteLine(square.ToString()); Console.WriteLine(square.GetArea() + " " + square.GetPerimeter()); Console.WriteLine(ellipse.ToString()); Console.WriteLine(ellipse.GetArea() + " " + ellipse.GetPerimeter()); }
static void Main(string[] args) { Point p1 = new Point(1, 2); Point p2 = new Point(5, 1); Point p3 = new Point(3, 5); Point p4 = new Point(1, 5); Triangle triangle = new Triangle(p1, p2, p3); //Console.WriteLine(triangle.GetArea()); //Console.WriteLine(triangle.GetPerimeter()); Console.WriteLine(triangle.ToString()); Ellipse ellipse = new Ellipse(5, 10); //Console.WriteLine(ellipse.GetPerimeter()); //Console.WriteLine(ellipse.GetArea()); Console.WriteLine(ellipse.ToString()); Rectangle rectangle = new Rectangle(p1,p2,p3,p4); //Console.WriteLine(rectangle.Width); //Console.WriteLine(rectangle.Heigth); //Console.WriteLine(rectangle.GetArea()); //Console.WriteLine(rectangle.GetPerimeter()); Console.WriteLine(rectangle.ToString()); }
static void Main(string[] args) { Point p1 = new Point(1, 2); Point p2 = new Point(5, 1); Point p3 = new Point(3, 5); Point p4 = new Point(1, 5); Triangle triangle = new Triangle(p1, p2, p3); //Console.WriteLine(triangle.GetArea()); //Console.WriteLine(triangle.GetPerimeter()); Console.WriteLine(triangle.ToString()); Ellipse ellipse = new Ellipse(5, 10); //Console.WriteLine(ellipse.GetPerimeter()); //Console.WriteLine(ellipse.GetArea()); Console.WriteLine(ellipse.ToString()); Rectangle rectangle = new Rectangle(p1, p2, p3, p4); //Console.WriteLine(rectangle.Width); //Console.WriteLine(rectangle.Heigth); //Console.WriteLine(rectangle.GetArea()); //Console.WriteLine(rectangle.GetPerimeter()); Console.WriteLine(rectangle.ToString()); }
private void Draw_Click(object sender, EventArgs e) { // Rectangle if (this.radioButtonRectangle.Checked == true) { int x = Convert.ToInt32(this.textBoxX.Text); int y = Convert.ToInt32(this.textBoxY.Text); int height = Convert.ToInt32(this.textBoxHeight.Text); int width = Convert.ToInt32(this.textBoxWidth.Text); myRectangle = new Rectangle(x, y, height, width); // fill or draw? fill = false; //txt_Display String info = myRectangle.ToString(); this.textBoxDisplay.Text = info; this.textBoxDisplay.Visible = true; } // Square if (this.radioButtonSquare.Checked == true) { int x = Convert.ToInt32(this.textBoxX.Text); int y = Convert.ToInt32(this.textBoxY.Text); int width = Convert.ToInt32(this.textBoxWidth.Text); mySquare = new Square(x, y, width); // fill or draw? fill = false; //txt_Display String info = mySquare.ToString(); this.textBoxDisplay.Text = info; this.textBoxDisplay.Visible = true; } // Circle if (this.radioButtonCircle.Checked == true) { int x = Convert.ToInt32(this.textBoxX.Text); int y = Convert.ToInt32(this.textBoxY.Text); int width = Convert.ToInt32(this.textBoxWidth.Text); myCircle = new Circle(x, y, width); // fill or draw? fill = false; //txt_Display String info = myCircle.ToString(); this.textBoxDisplay.Text = info; this.textBoxDisplay.Visible = true; } // Ellipse if (this.radioButtonEllipse.Checked == true) { int x = Convert.ToInt32(this.textBoxX.Text); int y = Convert.ToInt32(this.textBoxY.Text); int height = Convert.ToInt32(this.textBoxHeight.Text); int width = Convert.ToInt32(this.textBoxWidth.Text); myEllipse = new Ellipse(x, y, height, width); // fill or draw? fill = false; //txt_Display String info = myEllipse.ToString(); this.textBoxDisplay.Text = info; this.textBoxDisplay.Visible = true; } this.panelDrawing.Invalidate(); // it causes the control to be redrawn this.panelDrawing.Update(); this.Refresh(); }