PictureBox.CreateGraphics()和e.Graphics;的区别
我对C#并不太熟悉,只是知道一些基础,原来我一直认为PictureBox.CreateGraphics()和e.Graphics;都是获得了Graphics对象没什么区别,但是 我前一阵子遇到了这样一个问题:
向下面这样写就一切正常,如果将g=e.Graphics;改成pictureBox.CreateGraphics()就不好使了(pictureBox是一个已定义的控件)
private void pictureBox_Paint(object sender, PaintEventArgs e)
{
Graphics g;
g = e.Graphics;
\\g=pictureBox.CreateGraphics();
Pen myPen = Pens.Blue;
for (int i = 0; i < pictureBox.ClientRectangle.Width; i++)
{
g.DrawLine(myPen, new Point(i, 0), new Point(i, pictureBox.ClientRectangle.Bottom));
i += 10;
}
for (int j = 0; j < pictureBox.ClientRectangle.Height; j++)
{
g.DrawLine(myPen, new Point(0, j), new Point(pictureBox.ClientRectangle.Right, j));
j += 10;
}
g.Dispose();
}