我试图使签名面板在c# windowsform应用程序中输入是从绘图板
我的代码如下这段代码工作的线条画不点创建。
因此,请建议如何创建点和线。
{
Graphics graphics;
Boolean cusorMoving = false;
Pen cursorPen;
int cursorX = -1;
int cursorY = -1;
public SignPad()
{
InitializeComponent();
graphics = panel2.CreateGraphics();
cursorPen = new Pen(Color.Black, 2);
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
cursorPen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
cursorPen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
}
鼠标按下事件
private void panel2_MouseDown(object sender, MouseEventArgs e)
{
cusorMoving = true;
cursorX = e.X;
cursorY = e.Y;
}
private void panel2_MouseUp(object sender, MouseEventArgs e)
{
cusorMoving = false;
cursorX = -1;
cursorY = -1;
}
鼠标移动事件
private void panel2_MouseMove(object sender, MouseEventArgs e)
{
if (cursorX != -1 && cursorY != -1 && cusorMoving == true)
{
graphics.DrawLine(cursorPen, new Point(cursorX, cursorY), e.Location);
cursorX = e.X;
cursorY = e.Y;
}
}
1条答案
按热度按时间ncecgwcz1#
你需要将各个点存储在集合中,然后在Paint处理程序中分别绘制它们。每次向集合中添加一个点时,你还需要告诉面板在添加新线段的区域中进行绘制。类似于:
不要忘记在设计器中添加Paint处理程序,方法与添加MouseMove、MouseDown和MouseUp处理程序相同。