windows mobile中签字
鼠标(手写笔)轨迹坐标记录,然后画很多短的线
一:建立一个类,代表线段的两个端点(之所以用线段是由于需要连续的效果,否则如果鼠标移动的太快的话,会有断断续续的现象)
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中的内容保存起来,拱日后还原