摘要


画笔,定义用于绘制直线和曲线的对象。

正文


定义画笔:

Pen pen1 = new Pen(Color.Red, 1); //参数为颜色Color,单精度浮点数Sigle;宽度默认为1; Pen pen2 = Pen(new Brush(Color.BlueViolet), 10); // 使用指定的 Pen 和 Brush 初始化 Width 类的新实例。

使用画笔:

protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Pen pen1 = new Pen(Color.Red, 10); Pen pen2 = new Pen(Color.Blue, 2); Graphics g = e.Graphics; int height = 0; for (int i = 0; i < 20; i ) { if (i % 2 == 0) { height = 10; Point p1 = new Point(10, 10 height); Point p2 = new Point(200, 10 height); g.DrawLine(pen1, p1, p2); } else { height = 4; Point p1 = new Point(10, 10 height); Point p2 = new Point(200, 10 height); g.DrawLine(pen2, p1, p2); } } }

软笔笔锋入门教程(138.CGDI)(1)

再来一个例子

protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Pen pen1 = new Pen(Color.Red, 1); Pen pen2 = new Pen(Color.Blue, 1); Graphics g = e.Graphics; for (int i = 0; i < 20; i ) { g.DrawLines(pen1, new Point[] { new Point(100 i*20,50), new Point(50 i*20,100), new Point(150 i*20,100), new Point(100 i*20,50), }); } }

软笔笔锋入门教程(138.CGDI)(2)

,