只要执行了一个涉及到显示连接线段的操作,就可以设置连接线段的样式。为此,可以使用System.Drawing.Drawing2D命名空间中的LineJoin枚举的值,:Milter(默认值)、Beveled、MilterClipped和Round.
在下面的代码中,我们把Pen对象的LineJoin属性设置为值LineJoin.Bevel,然后用它绘制一个矩形:
1 private void Form1_Paint(object sender, PaintEventArgs e)
2 {
3 Graphics g = e.Graphics;
4 g.SmoothingMode = SmoothingMode.AntiAlias;
5 g.FillRectangle(Brushes.White, this.ClientRectangle);
6
7 Pen p = new Pen(Color.Black, 10);
8 p.LineJoin = LineJoin.Bevel;
9 e.Graphics.DrawRectangle(p, 20, 20, 60, 60);
10 p.Dispose();
11 }
显示的图形为:
可以用Brush(画笔)进行填充,如:
1 private void Form1_Paint(object sender, PaintEventArgs e)
2 {
3 Graphics g = e.Graphics;
4 g.SmoothingMode = SmoothingMode.AntiAlias;
5 SolidBrush b = new SolidBrush(Color.Crimson);
6 g.FillRectangle(b,20,20,40,40);
7 b.Dispose();
8 }
填充一个深红色的矩形