0
我想让位图出现在我的窗体中,但它不起作用。位图不会出现在窗体中
我的代码:
private void button2_Click(object sender, EventArgs e)
{
Graphics g = this.CreateGraphics();
Pen pen = new Pen(Color.Black);
Bitmap bitmap = new Bitmap(1000, 1000);
Graphics gfx = Graphics.FromImage(bitmap);
gfx.Clear(Color.Red);
for (int i = 0; i < 5; i++)
{
gfx.DrawRectangle(pen, i + 50, 50, 50, 50);
}
}
你为什么不把一个PictureBox放在你的窗体上并分配一个新的位图?借助表格本身会导致各种问题。 – nvoigt
此代码中没有任何内容正在尝试绘制位图。您正在内存位图上绘制矩形,但您不会自己绘制位图。 – DonBoitnott