只要執(zhí)行了一個(gè)涉及到顯示連接線段的操作,就可以設(shè)置連接線段的樣式。為此,可以使用System.Drawing.Drawing2D命名空間中的LineJoin枚舉的值,:Milter(默認(rèn)值)、Beveled、MilterClipped和Round.
在下面的代碼中,我們把Pen對象的LineJoin屬性設(shè)置為值LineJoin.Bevel,然后用它繪制一個(gè)矩形:
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(畫筆)進(jìn)行填充,如:
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 }
填充一個(gè)深紅色的矩形
|