Home > Net >  C # to do drawing board draw a straight line, which members will be
C # to do drawing board draw a straight line, which members will be

Time:09-24

With a picturebox mousemove events, when they draw a straight line with the mouse drawing lines, with the Clear words, before all the Clear, how to raise to achieve like Windows sketchpad draw a straight line???????
This bothers me a lot of days, few scores in all

CodePudding user response:

The complete code: https://download.csdn.net/download/caozhy/12082528

Problem solving, please stick to points

 using System; 
using System.Collections.Generic;
Using System.Com ponentModel;
Using System. The Data;
Using System. Drawing;
using System.Linq;
Using System. The Text;
Using System. Windows. Forms;

The namespace T395559890
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent();
Enclosing DoubleBuffered=true;
}

Private List Lines=new List (a);

Private Point? The pre.

Private void Form1_Paint (object sender, PaintEventArgs e)
{
The foreach (var item in lines)
{
Um participant raphics. DrawLine (Pens. Black, item. The Item1, item. The Item2);
}
}

Private void Form1_MouseMove (object sender, MouseEventArgs e)
{
If (e.B utton==System. Windows. Forms. MouseButtons. Left)
{
If (pre. HasValue)
{
Lines. The Add (new Tuple (pre) Value, new Point (e.X, e.Y)));
The Refresh ();
}
The pre=new Point (e.X, e.Y);
}
The else
{
If (pre. HasValue)
{
Lines. The Add (new Tuple (pre) Value, new Point (e.X, e.Y)));
The Refresh ();
}
The pre=null;
}
}
}
}

  •  Tags:  
  • C#
  • Related