您需要决定您想做什么:
您的代码是两者的混合,这就是它不起作用的原因。
这是如何绘制的onto the Control
:
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawEllipse(Pens.Red, new Rectangle(3, 4, 44, 44));
..
}
这是如何绘制的into the Image
of the PictureBox
:
void drawIntoImage()
{
using (Graphics G = Graphics.FromImage(pictureBox1.Image))
{
G.DrawEllipse(Pens.Orange, new Rectangle(13, 14, 44, 44));
..
}
// when done with all drawing you can enforce the display update by calling:
pictureBox1.Refresh();
}
两种绘制方式都是持久的。后者会更改图像的像素,而前者则不会。
因此,如果像素被绘制到图像中,并且您缩放、拉伸或移动图像,则像素将随之移动。绘制到 PictureBox 控件顶部的像素不会这样做!
当然,对于这两种绘制方式,您可以更改所有常用部分,例如绘制命令,也许添加一个FillEllipse
之前DrawEllipse
, the Pens
and Brushes
与他们的画笔类型和Colors
和尺寸。