滑鼠(手寫筆)軌跡座標記錄,然後畫很多短的線
一:建立一個類,代表線段的兩個端點(之所以用線段是由於需要連續的效果,否則如果滑鼠移動的太快的話,會有斷斷續續的現象)
public class DrawLine
{
private int _x1;
private int _y1;
private int _x2;
private int _y2;
public DrawLine(int X1, int Y1, int X2, int Y2)
{
_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;
}
}
}
二 在簽字的表單裡定義
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>();
}
並且在MouseDown,MouseMove,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;
}
可以將Points中的內容儲存起來,拱日後還原