GDI+ Pen Brush
以下介绍pen的一些属性:
1.画笔绘制方式
Pen.Alignment 属性设置当钢笔的宽度超过1像素的时候,该如何绘制有Center,Inset ,Outset,Left,right。
View Code
Pen a = new Pen(Color.Tomato,20);
a.Alignment = PenAlignment.Outset;
g.DrawRectangle(a,50,50, 100, 100);
a.Alignment = PenAlignment.Outset;
g.DrawRectangle(a,50,50, 100, 100);
2.定制短划线:
View Code
Pen a = new Pen(Color.Tomato,1);
a.Alignment = PenAlignment.Outset;
float[] f = { 15, 5, 10, 2, 30, 10 };
a.DashPattern = f;
g.DrawLine(a, 3f, 3f, 300f,3f);
a.Alignment = PenAlignment.Outset;
float[] f = { 15, 5, 10, 2, 30, 10 };
a.DashPattern = f;
g.DrawLine(a, 3f, 3f, 300f,3f);
3,绘制带图形的直线。
Pen a = new Pen(Color.Tomato,10);
a.StartCap = LineCap.Round;
a.EndCap = LineCap.ArrowAnchor;
g.DrawLine(a, 20f,20f, 300f,20f);
g.DrawLine(b, 3f, 9f, 300f, 9f);
a.StartCap = LineCap.Round;
a.EndCap = LineCap.ArrowAnchor;
g.DrawLine(a, 20f,20f, 300f,20f);
g.DrawLine(b, 3f, 9f, 300f, 9f);
同时也可以使用定制的线段端部图形。这要用到graphicspath类。
4,设置连接线段的样式
主要设置两条直线连接处的样式。
View Code
Pen a = new Pen(Color.Tomato,10);
a.LineJoin = LineJoin.Bevel;
a.LineJoin = LineJoin.Round;
a.LineJoin = LineJoin.Miter;
a.LineJoin = LineJoin.MiterClipped;
g.DrawRectangle(a,50,50, 100, 100);
a.LineJoin = LineJoin.Bevel;
a.LineJoin = LineJoin.Round;
a.LineJoin = LineJoin.Miter;
a.LineJoin = LineJoin.MiterClipped;
g.DrawRectangle(a,50,50, 100, 100);
5.Brush
Brush是一个抽象类,因此其子类有SolidBrush,TextureBrush,LineGradientBrush,PathGradientBrush