这取决于鼠标移动的速度,有时 MouseMove 事件会更频繁地触发,有时则不会。我认为这还取决于您的机器在该特定时刻加载了多少。如果你在两点之间画线,它们不会是弯曲的,而是直线的。相反,您应该查看Beziers和Splines。这样,您将获得基于几个点的曲线。
但是你可以用你的代码做点什么。每当您最后一次 mousedown 和当前 mousedown 事件之间的距离大于阈值时(您可以凭经验获得),您可以向曲线添加新点。下面是添加一个点的示例代码:
public bool isMouseDown { get; set; }
Point lastPoint = Point.Empty;
public double treshold { get; set; }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (isMouseDown)
{
pictureBox1.Capture = true; // I try to capture mouse here
Graphics g = Graphics.FromHwnd(this.pictureBox1.Handle);
if (Math.Sqrt(Math.Pow(e.X - lastPoint.X, 2) + Math.Pow(e.Y - lastPoint.Y, 2)) > treshold)
{
g.FillRectangle(new SolidBrush(Color.Black), (e.X + lastPoint.X)/2, (e.Y + lastPoint.Y)/2, 1, 1);
}
g.FillRectangle(new SolidBrush(Color.Black), e.X, e.Y, 1, 1);
lastPoint = new Point(e.X, e.Y);
}
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
isMouseDown = true;
lastPoint = new Point(e.X, e.Y);
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
isMouseDown = false;
}