我正在使用以下代码进行绘制。我不知道为什么要这样做。在它工作正常之前。当我添加“picBox.Image = new Bitmap(560, 464);”时 我的 form() 中的这一行,我添加了这个 Graphics.FromImage(picBox.Image)...
private void picBox_MouseDown(object sender, MouseEventArgs e)
{
draw = true;
x = e.X;
y = e.Y;
}
private void picBox_MouseMove(object sender, MouseEventArgs e)
{
if (draw)
{
//Graphics g = picBox.CreateGraphics();
switch (currItem)
{
case Item.Rectangle:
Graphics.FromImage(picBox.Image).FillRectangle(new SolidBrush(paintColor), x, y, e.X - x, e.Y - y);
break;
case Item.Ellipse:
Graphics.FromImage(picBox.Image).FillEllipse(new SolidBrush(paintColor), x, y, e.X - x, e.Y - y);
break;
}
picBox.Refresh();
Graphics.FromImage(picBox.Image).Dispose();
}
}
private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
draw = false;
lx = e.X;
ly = e.Y;
}