Example #1
0
        public static MyShape Create(ShapeTypeDefine shapeType, Point p1, Point p2)
        {
            MyShape shape = null;

            switch (shapeType)
            {
            case ShapeTypeDefine.LINE:
                shape = new MyLine(p1, p2);
                break;

            case ShapeTypeDefine.CIRCLE:
                shape = new MyCircle(p1, p2);
                break;

            case ShapeTypeDefine.ELLIPSE:
                shape = new MyEllipse(p1, p2);
                break;

            case ShapeTypeDefine.POLYGON:
                shape = new MyPolygon(p1, p2);
                break;

            case ShapeTypeDefine.POLYLINE:
                shape = new MyPolyline(p1, p2);
                break;

            case ShapeTypeDefine.BEZIER:
                shape = new MyBezier(p1, p2);
                break;

            case ShapeTypeDefine.RECTANGLE:
                shape = new MyRectangle(p1, p2);
                break;

            default:
                shape = new MyRectangle(p1, p2);
                break;
            }
            return(shape);
        }
Example #2
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFile = new OpenFileDialog();

            openFile.InitialDirectory = "d:\\";

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                shapes.Clear();
                string       filename = openFile.FileName;
                StreamReader streamReader = new StreamReader(filename);
                string       line, firstWord = null;
                while ((line = streamReader.ReadLine()) != null)
                {
                    if (line != "")
                    {
                        firstWord = line.Substring(0, line.IndexOf(" "));
                    }
                    switch (firstWord)
                    {
                    case "Line":
                        MyShape myLine = new MyLine();
                        myLine.Open(line);
                        shapes.Add(myLine);
                        break;

                    case "Rectangle":
                        MyShape myRectangle = new MyRectangle();
                        myRectangle.Open(line);
                        shapes.Add(myRectangle);
                        break;

                    case "Circle":
                        MyShape myCircle = new MyCircle();
                        myCircle.Open(line);
                        shapes.Add(myCircle);
                        break;

                    case "Ellipse":
                        MyShape myEllipse = new MyEllipse();
                        myEllipse.Open(line);
                        shapes.Add(myEllipse);
                        break;

                    case "Polygon":
                        MyShape myPolygon = new MyPolygon();
                        myPolygon.Open(line);
                        shapes.Add(myPolygon);
                        break;

                    case "Bezier":
                        MyShape myBezier = new MyBezier();
                        myBezier.Open(line);
                        shapes.Add(myBezier);
                        break;

                    case "Polyline":
                        MyShape myPolyline = new MyPolyline();
                        myPolyline.Open(line);
                        shapes.Add(myPolyline);
                        break;
                    }
                    pnlMain.Invalidate();
                    firstWord = "";
                }
            }
        }