在程序窗口上使用鼠标画图

  private Point pStart, pEnd;
        private bool isAllowDraw = false;
        private bool isOpenPen = false;
        private void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            if (isOpenPen)
            {
                isAllowDraw = true;
                pStart = pEnd = e.Location;
            }
        }

        private void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            if (isOpenPen)
            {
                isAllowDraw = false;
            }
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (isOpenPen && isAllowDraw)
            {
                pEnd = e.Location;

                Graphics g = this.CreateGraphics();
                g.SmoothingMode = SmoothingMode.HighQuality;//去掉锯齿
                System.Drawing.Pen pen = new System.Drawing.Pen(Color.Red, 4);
                g.DrawLine(pen, pStart, pEnd);

                pStart = pEnd;
            }
        }

  

相关文章:

  • 2022-12-23
  • 2021-12-18
  • 2021-09-14
  • 2021-09-24
  • 2021-09-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-09
  • 2021-08-13
  • 2021-06-04
  • 2022-02-15
  • 2021-11-17
  • 2021-09-07
  • 2021-08-29
相关资源
相似解决方案