我的问题与 Stack Overflow 的这个问题 在 C# 中使用鼠标单击在 picturebox 上绘制线条 相关,但当鼠标按钮松开后,绘制的线条会消失。我该如何解决这个问题?
private void GainBox_MouseDn(object sender, MouseEventArgs e)
{
mouse_dn = true;
}
private void GainBox_MouseMv(object sender, MouseEventArgs e)
{
//Line drawn from lookup table
if (mouse_dn)
{
img = new Bitmap(256, 256);
//Get the coordinates (x, y) for line from lookup table.
for (x = x1; x < x2; x++)
img.SetPixel(x, y, Color.Red);
//Same for y coordinate
}
GainBox.Refresh();
}
private void GainBox_MouseUp(object sender, MouseEventArgs e)
{
mouse_dn = false;
}