十字光标定位

Posted on 2019-01-15 21:30  努力成长静待花开  阅读(344)  评论(0编辑  收藏  举报

实现效果:

  

知识运用:

  Graphics对象的DrawLine方法

  public void DrawLine (Pen pen, Point pt1,Point pt2)

  public void DrawLine (Pen pen, int x1,int y1,int x2,int y2)

实现代码:

        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.DrawLine(new Pen(Color.Black,2),new Point(0,e.Y),new Point(this.Width,e.Y));
            g.DrawLine(new Pen(Color.Black, 2), new Point(e.X, 0), new Point(e.X,this.Height));
        }