c# winform构建平面图
时间: 2023-08-27 22:05:00 浏览: 23
在C# WinForm中构建平面图可以使用GDI+绘图技术,具体步骤如下:
1. 创建一个WinForm项目,添加一个PictureBox控件作为画布。
2. 在PictureBox的Paint事件中获取Graphics对象,用来绘制图形。
3. 使用Graphics对象的DrawLine、DrawRectangle等方法来绘制图形。
4. 可以使用Pen对象来设置绘制线条的颜色、宽度等属性。
5. 可以使用Brush对象来设置填充图形的颜色。
6. 可以使用Path对象来绘制复杂的图形。
下面是一个简单的示例代码,绘制一个矩形和一条线段:
```
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
Pen pen = new Pen(Color.Red, 2);
Brush brush = new SolidBrush(Color.Blue);
Rectangle rect = new Rectangle(50, 50, 100, 80);
g.DrawRectangle(pen, rect);
g.FillRectangle(brush, rect);
Point p1 = new Point(50, 50);
Point p2 = new Point(150, 130);
g.DrawLine(pen, p1, p2);
}
```
这样就可以在PictureBox上绘制一个矩形和一条线段了。根据需要,可以使用更多的绘图方法和对象来绘制其他形状的图形。
相关推荐
















