示例#1
0
        private Shape GetShape(ShapeType type, Point p1, Point p2)
        {
            if (type == ShapeType.Rectangle)
            {
                MyRectangle r = new MyRectangle();

                int w = Math.Abs(p1.X - p2.X);
                int h = Math.Abs(p1.Y - p2.Y);

                r.Location = GetMinPoint(p1, p2);
                r.Height   = h;
                r.Width    = w;

                return(r);
            }
            else if (type == ShapeType.Circle)
            {
                MyCircle r = new MyCircle();

                int w = Math.Abs(p1.X - p2.X);
                int h = Math.Abs(p1.Y - p2.Y);

                r.Location = GetMinPoint(p1, p2);
                r.Height   = h;
                r.Width    = w;

                return(r);
            }
            else
            {
                MyLine line = new MyLine();
                line.Location    = p1;
                line.EndLocation = p2;



                return(line);
            }
        }
示例#2
0
        private void DrawShape(Shape s)
        {
            if (s is MyRectangle)
            {
                MyRectangle r = s as MyRectangle;
                graphics.DrawRectangle(pen,
                                       r.Location.X, r.Location.Y, r.Width, r.Height);
            }
            else if (s is MyCircle)
            {
                MyCircle circle = s as MyCircle;

                graphics.DrawEllipse(pen,
                                     circle.Location.X, circle.Location.Y,
                                     circle.Width, circle.Height);
            }
            else if (s is MyLine)
            {
                MyLine l = s as MyLine;

                graphics.DrawLine(pen, l.Location, l.EndLocation);
            }
        }
示例#3
0
        private void DrawShape(Shape s)
        {
            if (s is MyPencil)
            {
                MyPencil p = s as MyPencil;

                if (p.Points.Count < 1)
                {
                    return;
                }

                for (int i = 1; i < p.Points.Count; i++)
                {
                    graphics.DrawLine(pen, p.Points[i - 1], p.Points[i]);
                }
            }
            else if (s is MyRectangle)
            {
                MyRectangle r = s as MyRectangle;
                graphics.DrawRectangle(pen,
                                       r.Location.X, r.Location.Y, r.Width, r.Height);
            }
            else if (s is MyCircle)
            {
                MyCircle circle = s as MyCircle;

                graphics.DrawEllipse(pen,
                                     circle.Location.X, circle.Location.Y,
                                     circle.Width, circle.Height);
            }
            else if (s is MyLine)
            {
                MyLine l = s as MyLine;

                graphics.DrawLine(pen, l.Location, l.EndLocation);
            }
        }