/// <summary> /// Draw a circle, by capturing 2 clicks to define the diameter. /// </summary> /// <param name="e"></param> private void CreateCircle(MouseEventArgs e) { if (clicknumber == 0) { one = new PointF(e.X, e.Y); clicknumber = 1; } else { two = new PointF(e.X, e.Y); clicknumber = 0; Graphics g = this.CreateGraphics(); Pen blackpen = new Pen(Color.Black); Circle aShape = new Circle(one, two); activeShapes.Add(aShape); aShape.Draw(g); } RefreshDrawings(); }
static void Main(string[] args) { //Shape shape = new Shape(); Shape circle = new Circle(); circle.Draw(); List <Shape> shapes = new List <Shape>(); // use polymorphis to store objects shapes.Add(new Circle()); shapes.Add(new Square()); shapes.Add(new Circle()); shapes.Add(new Square()); Console.WriteLine("Loop through all drawing objects in a list:"); foreach (Shape shape in shapes) { shape.Draw(); // "Draw Circle!" "Draw Square!" ... } }