在PictureBox控件上进行图形绘制,可以通过以下步骤实现:
private void Form1_Load(object sender, EventArgs e)
{
pictureBox1.Paint += new PaintEventHandler(pictureBox1_Paint);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// 在这里编写绘制图形的代码,例如绘制一个矩形
Pen pen = new Pen(Color.Red);
Rectangle rect = new Rectangle(10, 10, 100, 100);
e.Graphics.DrawRectangle(pen, rect);
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// 绘制一个矩形
Pen pen = new Pen(Color.Red);
Rectangle rect = new Rectangle(10, 10, 100, 100);
g.DrawRectangle(pen, rect);
// 绘制一个椭圆
pen = new Pen(Color.Blue);
rect = new Rectangle(50, 50, 100, 50);
g.DrawEllipse(pen, rect);
}
通过以上两种方法,在PictureBox控件上进行图形绘制。可以根据需要绘制各种图形,调整颜色、大小等属性,实现自定义的图形效果。