求一直线类,希望从一基类中继承,具有删除,复制,修改,拖动的功能,谢谢

解决方案 »

  1.   

    用 javascript 实现  百度一下 很多代码  我就不重复写了
      

  2.   

    http://download.csdn.net/source/1907620
    http://topic.csdn.net/t/20020424/10/671844.html
    //声明画笔 
    Pen   myPen   =   new   Pen(Color.Red); //重载OnPaint函数 
    protected   override   void   OnPaint(PaintEventArgs   e) 

    Graphics   g   =   e.Graphics; 
                                        myPen.Width   =   5; 
    g.DrawLine(myPen,1,1,100,100); }
      

  3.   

    Drawing Lines in GDI+
      

  4.   

    我初学,遇到点问题:我在书上抄的类,调试没过:public struct RectArea
        {
            public Point LeftTop;
            public Point RightBottom;
        }    public struct DrawPara
        {
            public Color color;
            public DashStyle style;
            public int lineWidth;
            public DrawPara(Color color1, DashStyle style1, int lineWidth1)
            {
                color = color1;
                style = style1;
                lineWidth = lineWidth1;
            }
        }    // 接口类
        interface IgraphicsOp
        {
            void Move(int x, int y, Graphics g);
            void MoveTo(int x, int y, Graphics g);
            void Draw(Graphics g);
        }    // 图元基类
        public abstract class Elements : ICloneable,IgraphicsOp
        {
            public DrawPara para;        public Elements(DrawPara para1)
            {
                para = para1;
            }        public Elements()
            {
            }        public DrawPara Para
            {
                get
                {
                    return Para;
                }            set
                {
                    Para = value;
                }
            }        public abstract decimal Area();        public abstract RectArea OverRect();        public abstract void _Move(int x, int y);        public abstract void _MoveTo(int x, int y);        public abstract void Draw(Graphics g);        public void Move(int x, int y, Graphics g)
            {
                Color oldColor = this.para.color;
                //this.para.color = new Pen(this.para.color, this.para.lineWidth);
                Draw(g);
                _Move(x, y);
                this.para.color = oldColor;
                Draw(g);
            }        public void MoveTo(int x, int y, Graphics g)
            {
                Color oldColor = this.para.color;
                //this.para.color = new Pen(this.para.color, this.para.lineWidth);
                Draw(g);
                _MoveTo(x, y);
                this.para.color = oldColor;
                Draw(g);
            }        public virtual object Clone()
            {
                return MemberwiseClone();
            }
        }    // 直线类
        public abstract class Line : Elements
        {
            private Point start, end;        public Line(Point st, Point ed, DrawPara Para)
                : base(Para)
            {
                start.X = st.X;
                start.Y = st.Y;
                end.X = ed.X;
                end.Y = ed.X;
            }        public Line()
            {
            }        public override decimal Area()
            {
                return 0.0M; 
            }        public override RectArea OverRect()
            {
                RectArea Rect = new RectArea();
                if (start.X > end.X)
                {
                    Rect.LeftTop.X = end.X;
                    Rect.RightBottom.X = start.X;
                }
                else
                {
                    Rect.LeftTop.X = start.X;
                    Rect.RightBottom.X = end.X;
                }            if (start.Y > end.Y)
                {
                    Rect.LeftTop.Y = end.Y;
                    Rect.RightBottom.Y = start.Y;
                }
                else
                {
                    Rect.LeftTop.Y = start.Y;
                    Rect.RightBottom.Y = end.Y;
                }            return Rect;
            }        public override void Draw(Graphics g)
            {
                using (Pen myPen = new Pen(para.color, para.lineWidth))
                {
                    myPen.DashStyle = para.style;
                    g.DrawLine(myPen, start.X, start.Y, end.X, end.Y);
                }
            }        public override void _Move(int x, int y)
            {
                Size size = new Size(x, y);
                this.start += size;
                this.end += size;
            }        public override void _MoveTo(int x, int y)
            {
                _Move(x-start.X, y-start.Y);
            }        public override object Clone()
            {
                Line newLine = new Line();
                newLine.para = para;
                newLine.start = new Point(start.X, start.Y);
                newLine.end = new Point(end.X, end.Y);
                return newLine;
            }    }    // 矩形类
        public class Rectangle : Elements
        {
            private Point LeftTop, RightBottom;        public Rectangle(Point lt, Point rb, DrawPara Para)
                : base(Para)
            {
                if (lt.X >= rb.X || lt.Y >= rb.Y)
                    throw new ArgumentNullException();
                LeftTop.X = lt.X;
                LeftTop.Y = lt.Y;
                RightBottom.X = rb.X;
                RightBottom.Y = rb.Y;
            }        public Rectangle()
            {
            }        public override decimal Area()
            {
                return (RightBottom.X - LeftTop.X) * (RightBottom.Y - LeftTop.Y);
            }        public static explicit operator RectArea(Rectangle value)
            {
                RectArea a = new RectArea();
                a.LeftTop = value.LeftTop;
                a.RightBottom = value.RightBottom;
                return a;
            }        public override RectArea OverRect()
            {
                return (RectArea)this;
            }        public override void Draw(Graphics g)
            {
                using (Pen myPen = new Pen(para.color, para.lineWidth))
                {
                    myPen.DashStyle = para.style;
                    g.DrawRectangle(myPen, LeftTop.X, LeftTop.Y, RightBottom.X, RightBottom.Y);
                }
            }        public override void _Move(int x, int y)
            {
                Size size = new Size(x, y);
                this.LeftTop += size;
                this.RightBottom += size;
            }        public override void _MoveTo(int x, int y)
            {
                _Move(x - LeftTop.X, y - LeftTop.Y);
            }        public override object Clone()
            {
                Rectangle rectangle = new Rectangle();
                rectangle.para = para;
                rectangle.LeftTop = new Point(LeftTop.X, LeftTop.Y);
                rectangle.RightBottom = new Point(RightBottom.X, RightBottom.Y);
                return rectangle;
            }
        }
      

  5.   

    public override object Clone()
            {
                Line newLine = new Line();  //这报错:错误 1 无法创建抽象类或接口“Stone.Tools.Files.Line”的实例 G:\MyJob\5TMonitor\5TMonitor\5TMonitor\Stone_File.cs 451 28 5TMonitor            newLine.para = para;
                newLine.start = new Point(start.X, start.Y);
                newLine.end = new Point(end.X, end.Y);
                return newLine;
            }
      

  6.   

    http://www.codeproject.com/KB/GDI-plus/lineditor.aspx
      

  7.   

    抽象类(以abstract修饰的类)是不能创建实例的//你把
    public abstract class Line : Elements
    //改为
    public class Line : Elements
    //试试
      

  8.   

    public void Move(int x, int y, Graphics g)
      {
      Color oldColor = this.para.color;
      //this.para.color = new Pen(this.para.color, this.para.lineWidth);//这句怎么得到背景色呢?
      Draw(g);
      _Move(x, y);
      this.para.color = oldColor;
      Draw(g);
      }
    移动时需要用背景色覆盖原来的,怎么得到背景色呢?谢谢
      

  9.   

    up一下public void Move(int x, int y, Graphics g)
      {
      Color oldColor = this.para.color;
      //this.para.color = new Pen(this.para.color, this.para.lineWidth);//这句怎么得到背景色呢?
      Draw(g);
      _Move(x, y);
      this.para.color = oldColor;
      Draw(g);
      }
    移动时需要用背景色覆盖原来的,怎么得到背景色呢?谢谢
      

  10.   


    http://www.codeproject.com/KB/graphics/drawtools.aspx