GDI+ 通过笔刷创建钢笔并绘制图案
先上图:
提示:可通过笔刷来创建钢笔并绘制图形,以上是通过HatchBrush 来创建钢笔的。
View Code
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
Pen hp = new Pen(hb, 8);
g.DrawRectangle(hp,12,12,200,200);
hb.Dispose();
}
{
Graphics g = e.Graphics;
HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
Pen hp = new Pen(hb, 8);
g.DrawRectangle(hp,12,12,200,200);
hb.Dispose();
}
还可以通过LinearGridentBrush来创建钢笔,从而绘制吩咐多彩的边框。如图;
代码如下:
View Code
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(2, 2), new Point(19, 2), Color.Blue, Color.Brown);
Pen hp = new Pen(lgb, 8);
g.DrawRectangle(hp,12,12,200,200);
}
{
Graphics g = e.Graphics;
// HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(2, 2), new Point(19, 2), Color.Blue, Color.Brown);
Pen hp = new Pen(lgb, 8);
g.DrawRectangle(hp,12,12,200,200);
}
通过笔刷创建钢笔之后,我们可以通过钢笔的各种属性来绘制图形,如图:
代码如下:
View Code
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
// HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(2, 2), new Point(19, 2), Color.Blue, Color.Brown);
Pen hp = new Pen(lgb, 8);
hp.StartCap = LineCap.Round;
hp.EndCap = LineCap.DiamondAnchor;
g.DrawLine(hp,5,300,120,300);
g.DrawRectangle(hp,12,12,200,200);
}
{
Graphics g = e.Graphics;
// HatchBrush hb = new HatchBrush(HatchStyle.NarrowHorizontal, Color.Red, Color.White);
LinearGradientBrush lgb = new LinearGradientBrush(new Point(2, 2), new Point(19, 2), Color.Blue, Color.Brown);
Pen hp = new Pen(lgb, 8);
hp.StartCap = LineCap.Round;
hp.EndCap = LineCap.DiamondAnchor;
g.DrawLine(hp,5,300,120,300);
g.DrawRectangle(hp,12,12,200,200);
}
因此可以利用笔刷来创建钢笔来绘制各种东西。