Esempio n. 1
0
        public static Shape CreateShape(string value)
        {
            Shape  shape         = null;
            string shapeCategory = value.Substring(0, value.IndexOf(";"));

            switch (shapeCategory)
            {
            case "圆":
                shape = new Circle();
                break;

            case "点":
                shape = new Dot();
                break;

            case "矩形":
                shape = new MyRect();
                break;

            case "直线":
                shape = new Line();
                break;

            case "三角形":
                shape = new Triangle();
                break;

            case "文字":
                shape = new MyText();
                break;

            case "曲线":
                shape = new Curve();
                break;
            }
            shape.FromString(value);
            return(shape);
        }
Esempio n. 2
0
        public static Shape CreateShape(XmlNode node)
        {
            Shape shape = null;

            switch (node.Name)
            {
            case "Circle":
                shape = new Circle();
                break;

            case "Dot":
                shape = new Dot();
                break;

            case "Triangle":
                shape = new Triangle();
                break;

            case "Rectangle":
                shape = new MyRect();
                break;

            case "Curve":
                shape = new Curve();
                break;

            case "Text":
                shape = new MyText();
                break;

            case "Line":
                shape = new Line();
                break;
            }
            shape.FromXML(node);
            return(shape);
        }
Esempio n. 3
0
        private void FormDocument_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }

            int shapeCount = this.document.Shapes.Count;

            switch (this.FormMain.CurrentShape)
            {
            case ShapeCategory.点:
                break;

            case ShapeCategory.直线:
                //int lineCount = this.document.Lines.Count;

                if (shapeCount > 0)
                {
                    Line lastline = (Line)this.document.Shapes[shapeCount - 1];
                    lastline.EndPoint = e.Location;
                }
                break;

            case ShapeCategory.曲线:

                if (shapeCount > 0)
                {
                    Curve lastCurve = (Curve)this.document.Shapes[shapeCount - 1];
                    lastCurve.Points.Add(e.Location);
                }
                break;

            case ShapeCategory.圆:

                if (shapeCount > 0)
                {
                    Circle lastCircle = (Circle)this.document.Shapes[shapeCount - 1];
                    lastCircle.MouseLocation = e.Location;
                    lastCircle.Status        = ShapeStatus.预览;
                    lastCircle.Radius        = (float)Math.Sqrt(
                        Math.Pow(e.Location.X - lastCircle.CenterPoint.X, 2) +
                        Math.Pow(e.Location.Y - lastCircle.CenterPoint.Y, 2)
                        );
                }
                break;

            case ShapeCategory.矩形:

                if (shapeCount > 0)
                {
                    MyRect     lastRectF  = (MyRect)this.document.Shapes[shapeCount - 1];
                    RectangleF rectangleF = RectangleF.Empty;    //赋值给rectangleF



                    rectangleF.X = (e.Location.X < startPoint.X) ? e.Location.X : startPoint.X;
                    rectangleF.Y = (e.Location.Y < startPoint.Y) ? e.Location.Y : startPoint.Y;

                    rectangleF.Width  = Math.Abs(e.Location.X - startPoint.X);
                    rectangleF.Height = Math.Abs(e.Location.Y - startPoint.Y);

                    lastRectF.RectF = rectangleF;    //这是什么意思? 为什么又赋值回去
                }
                break;

            case ShapeCategory.角形:

                switch (this.mouseClientCount)
                {
                case 0:
                    break;

                case 1:
                    if (shapeCount > 0)
                    {
                        Triangle lastTriangle = (Triangle)this.document.Shapes[shapeCount - 1];
                        lastTriangle.B = lastTriangle.C = e.Location;
                    }
                    break;

                case 2:
                    if (shapeCount > 0)
                    {
                        Triangle lastTriangle = (Triangle)this.document.Shapes[shapeCount - 1];
                        lastTriangle.C = e.Location;
                    }
                    break;
                }
                break;

            case ShapeCategory.文字:
                break;
            }
            this.DrawShapes();
        }
Esempio n. 4
0
        private void FormDocument_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            if (this.FormMain == null)
            {
                return;
            }

            ShapeCategory shapeCategory = this.FormMain.CurrentShape;

            switch (shapeCategory)
            {
            case ShapeCategory.点:
                Dot dot = new Dot();
                dot.Position = e.Location;
                dot.Color    = this.FormMain.CurrentColor;
                dot.Weight   = this.FormMain.CurrentWeight;
                this.document.AddShape(dot);

                break;

            case ShapeCategory.直线:
                Line line = new Line();
                line.StartPoint = e.Location;
                line.EndPoint   = e.Location;
                line.Color      = this.FormMain.CurrentColor;
                line.Weight     = this.FormMain.CurrentWeight;
                line.DashStyle  = this.FormMain.CurrentDashStyle;
                this.document.AddShape(line);

                break;

            case ShapeCategory.曲线:
                Curve curve = new Curve();
                curve.Color     = this.FormMain.CurrentColor;
                curve.DashStyle = this.FormMain.CurrentDashStyle;
                curve.Weight    = this.FormMain.CurrentWeight;
                curve.Points.Add(e.Location);

                this.document.AddShape(curve);
                break;

            case ShapeCategory.圆:
                Circle circle = new Circle();
                circle.Color         = this.FormMain.CurrentColor;
                circle.DashStyle     = this.FormMain.CurrentDashStyle;
                circle.Weight        = this.FormMain.CurrentWeight;
                circle.CenterPoint   = e.Location;
                circle.MouseLocation = e.Location;
                circle.Status        = ShapeStatus.预览;

                this.document.AddShape(circle);

                break;

            case ShapeCategory.矩形:
                this.startPoint = e.Location;

                MyRect myRect = new MyRect();    //new一个Myrect(自定义的类)对象
                myRect.Color     = this.FormMain.CurrentColor;
                myRect.DashStyle = this.FormMain.CurrentDashStyle;
                myRect.Weight    = this.FormMain.CurrentWeight;

                RectangleF rectangleF = new RectangleF();    //new一个RectangleF(系统定义的结构?)对象
                rectangleF.X      = e.Location.X;
                rectangleF.Y      = e.Location.Y;
                rectangleF.Width  = 0f;
                rectangleF.Height = 0f;

                myRect.RectF = rectangleF;    //把
                this.document.AddShape(myRect);
                break;

            case ShapeCategory.角形:
                //int triangleCount = this.document.Triangles.Count;

                int shapeCount = this.document.Shapes.Count;
                switch (this.mouseClientCount)
                {
                case 0:
                    Triangle triangle = new Triangle();

                    triangle.Color     = this.FormMain.CurrentColor;
                    triangle.DashStyle = this.FormMain.CurrentDashStyle;
                    triangle.Weight    = this.FormMain.CurrentWeight;
                    triangle.A         = triangle.B = triangle.C = e.Location;
                    this.document.AddShape(triangle);
                    break;

                case 1:
                    if (shapeCount > 0)
                    {
                        Triangle lastTriangle = (Triangle)this.document.Shapes[shapeCount - 1];
                        lastTriangle.B = lastTriangle.C = e.Location;
                    }
                    break;

                case 2:
                    if (shapeCount > 0)
                    {
                        Triangle lastTriangle = (Triangle)this.document.Shapes[shapeCount - 1];
                        lastTriangle.C = e.Location;
                    }
                    break;
                }
                break;

            case ShapeCategory.文字:

                MyText myText = new MyText();
                myText.Color    = this.FormMain.CurrentColor;
                myText.Weight   = this.FormMain.CurrentWeight * 10f;
                myText.Position = e.Location;
                this.document.AddShape(myText);

                this.Controls.Clear();

                TextBox textBox = new TextBox();
                textBox.Multiline    = true;
                textBox.Location     = e.Location;
                textBox.Height       = (int)(this.FormMain.CurrentWeight * 10 * 4f);
                textBox.Width        = 60 * textBox.Height;
                textBox.Font         = new Font("微软雅黑", myText.Weight);
                textBox.TextChanged += textBox_TextChanged;    //委托与事件

                this.Controls.Add(textBox);

                break;
            }
            this.DrawShapes();
        }