日期:2014-05-17  浏览次数:20695 次

在pictureBox1上画了一个圆,但把窗体最小化以后再最大化,这个圆就消失了,也无法保存这个圆
下面的代码的确在pictureBox1上画了一个圆,但把窗体最小化以后再最大化,这个圆就消失了,也无法保存这个圆

            Graphics g = pictureBox1.CreateGraphics();
            Pen pen = new Pen(Color.Red, 1);
            g.DrawEllipse(pen, 50, 50, 50, 50);

执行
      Bitmap bit = new Bitmap(pictureBox1.Width, pictureBox1.Height);
            pictureBox1.DrawToBitmap(bit, pictureBox1.ClientRectangle);
            bit.Save("C:\\Picture1.bmp", System.Drawing.Imaging.ImageFormat.Bmp);
发现Picture1.bmp中也没有这个圆。

------解决方案--------------------

Bitmap memoryBuffer = new Bitmap(pictureBox1.Width,pictureBox1.Height);
Graphics g = Graphics.FromImage(memoryBuffer);
Pen pen = new Pen(Color.Red, 1);
g.DrawEllipse(pen, 50, 50, 50, 50);
g.Dispose();
pictureBox1.Image = memoryBuffer;