软笔笔锋入门教程(138.CGDI)
摘要
画笔,定义用于绘制直线和曲线的对象。
正文
定义画笔:
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);
}
}
}
再来一个例子
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),
});
}
}
,
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com