coordinates of the mouse (PEN) trajectory, draw a lot of short lines.
1. Create a class to represent the two endpoints of a line segment. (the reason why the line segment is used is due to the continuous effect. Otherwise, if the mouse moves too fast, this may occur intermittently.)
public class drawline
{< br> private int _ x1;
private int _ Y1;
private int _ X2;
private int _ Y2;
Public drawline (INT X1, int Y1, int X2, int Y2)
{< br> _ X1 = x1;
_ Y1 = Y1;
_ X2 = x2;
_ y2 = Y2;
}
Public int X1
{
Get
{
Return _ x1;
}
Set
{
_ X1 = value;
}
}
Public int Y1
{
Get
{
Return _ Y1;
}
Set
{
_ Y1 = value;
}
}
Public int X2
{
Get
{
Return _ X2;
}
Set
{
_ X2 = value;
}
}
Public int Y2
{
Get
{
Return _ Y2;
}
Set
{
_ Y2 = value;
}
}
}
2. Define in the signed form
Private int x1;
Private int X2;
Private int Y1;
Private int Y2;
Private system. Drawing. Pen mpen = new pen (system. Drawing. color. Black, 2 );
Private bool bmouse = false;
Public System. Collections. Generic. List <drawline> points;
Private void signature_load (Object sender, eventargs E)
{
Points = new list <drawline> ();
}
You can also perform the following operations in mousedown, mousemove, and mouseup:
Private void signature_mousedown (Object sender, mouseeventargs E)
{
Bmouse = true;
X1 = E. X;
Y1 = E. Y;
}
Private void signature_mousemove (Object sender, mouseeventargs E)
{
If (! Bmouse)
{
Return;
}
Else
{
Graphics g;
X2 = E. X;
Y2 = E. Y;
G = This. creategraphics ();
Drawline point = new drawline (x1, Y1, X2, Y2 );
Points. Add (point );
G. drawline (mpen, X1, Y1, X2, Y2 );
X1 = x2;
Y1 = Y2;
}
}
Private void signature_mouseup (Object sender, mouseeventargs E)
{
Bmouse = false;
}
You can save the content in points and restore it later.