void DrawFigure(int id) { gr = panel1.CreateGraphics(); switch (id) { case 1: MyRectangle rect = new MyRectangle(p1x, p1y, p2x, p2y); figs.Add(rect); rect.Draw(gr); break; case 2: int cx, cy; double r = Math.Sqrt(Math.Pow(p2x - p1x, 2) + Math.Pow(p2y - p1y, 2)); cx = p1x - (int)r; cy = p1y - (int)r; MyCircle circ = new MyCircle(cx, cy, r); figs.Add(circ); circ.Draw(gr); break; } }
void DrawFigure(FigureName name) { gr = panel1.CreateGraphics(); switch (name) { case FigureName.Rectangle: MyFigure rect; Calculate(p1x, p1y, p2x, p2y); rect = new MyRectangle(p1x, p1y, width, height); figs.Add(rect); rect.Draw(gr); break; case FigureName.Circle: double r = Math.Sqrt(Math.Pow(p2x - p1x, 2) + Math.Pow(p2y - p1y, 2)); MyFigure circ = new MyCircle(p1x, p1y, r); figs.Add(circ); circ.Draw(gr); break; case FigureName.Vagon: MyFigure vagon; Calculate(p1x, p1y, p2x, p2y); vagon = new MyVagon(p1x, p1y, width, height); figs.Add(vagon); vagon.Draw(gr); break; case FigureName.Train: MyTrain train; Calculate(p1x, p1y, p2x, p2y); train = new MyTrain(p1x, p1y, width, height, (int)vagcount.Value); figs.Add(train); train.Draw(gr); break; } }