当表单进入屏幕时,我正在努力使用 invalidate 方法重绘图形 图形未重绘 我试图从图形中创建一个图像,以便使用 invalidate 方法重绘它,但它没有工作可以有人帮助编辑代码并以简单的方式完成,因为我仍然是初学者,非常感谢
private void squareButton_Click(object sender, EventArgs e)
{
// Declaring a new graphics object has been assigned null
Graphics objGraphics = null;
// This will create the picture graphics to be drawn in the picturebox
objGraphics = PictureBox1.CreateGraphics();
// This will redraw the picture box with a fill chosen after the systemcolors
objGraphics.Clear(SystemColors.ControlDark);
// This will draw the rectangle with a red pen 10,10 represent position and 50,50 reprsent the width and height
objGraphics.DrawRectangle(Pens.Red, 10, 10, 50, 50);
// This will draw the rectangle
objGraphics.Dispose();
Bitmap imgbit = (Bitmap)Picturebox.Image;
Graphics.FromImage(imgbit);
picturebox.invalidate();
// This is not redrawing the graphic it just shows a blank form
}