Bitmap bitmap = new Bitmap(panel1.Height,panel1.Width);
Graphics gc = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.Purple);
gc.DrawRectangle(pen, 0, 0, 40,40);
SolidBrush brush = new SolidBrush(Color.Black);
gc.FillRectangle(brush,0,0,20,20);
PictureBox picture = new PictureBox();
picture.Image = bitmap;
panel1.Controls.Add(picture);
Graphics gc = Graphics.FromImage(bitmap);
Pen pen = new Pen(Color.Purple);
gc.DrawRectangle(pen, 0, 0, 40,40);
SolidBrush brush = new SolidBrush(Color.Black);
gc.FillRectangle(brush,0,0,20,20);
PictureBox picture = new PictureBox();
picture.Image = bitmap;
panel1.Controls.Add(picture);
本文介绍了一种使用C#绘制矩形并填充颜色的方法,并展示了如何将绘制完成的位图显示在PictureBox中。通过创建Bitmap对象及Graphics对象,利用Pen和SolidBrush设置线条和填充颜色,实现了基本图形的绘制。
3297

被折叠的 条评论
为什么被折叠?



