C#中几种画刷的详细使用

C#中提供了好几种画刷的使用,最近一直在用这个,今天就总结一下这几种画刷的使用,便于以后查看!

1. 创建透明画刷

Size size = this.Size;
Point pt = this.Location;

//创建透明画刷
Color tcolor = Color.FromArgb(80, 222, 252, 249);
Brush tbrush = new SolidBrush(tcolor);
Rectangle trect = new Rectangle(pt.X, pt.Y, size.Width, 20);
Brush fontbrush = new SolidBrush(Color.Black);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y));
e.Graphics.FillRectangle(tbrush, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);

2. 创建线性渐变色画刷(接第一步的代码)

//创建线性渐变色画刷
trect.Y += 30;
LinearGradientBrush lgbrush = new LinearGradientBrush(trect,
                                                                  Color.FromArgb(222, 200, 249),
                                                                  Color.FromArgb(222, 252, 249),
                                                                  LinearGradientMode.Vertical);            
e.Graphics.FillRectangle(lgbrush, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y + 30));

3. 创建普通画刷(接第二步的代码)

//创建普通画刷
trect.Y += 30;
Brush brush = new SolidBrush(Color.FromArgb(222, 252, 249));
e.Graphics.FillRectangle(brush, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y + 60));

4. 创建阴影画刷(接第三步的代码)

//创建阴影画刷
trect.Y += 30;
Brush hbrush = new HatchBrush(HatchStyle.DarkVertical, Color.FromArgb(222, 200, 249), Color.FromArgb(222, 252, 249));            
e.Graphics.FillRectangle(hbrush, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y + 90));

5. 创建纹理画刷(接第四步的代码)
//创建纹理画刷
trect.Y += 30;
string path = "C:\\1.jpg";
Image image = Image.FromFile(path);
Brush txbursh = new TextureBrush(image, WrapMode.Tile);
e.Graphics.FillRectangle(txbursh, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y + 120));

6. 创建路径画刷(接第五步的代码)

//创建路径画刷
trect.Y += 30;
Point[] points = { new Point(pt.X, pt.Y + 150),
                               new Point(pt.X + size.Width, pt.Y + 150),
                               new Point(pt.X + size.Width, pt.Y + 170),
                               new Point(pt.X, pt.Y + 170)};
PathGradientBrush pgbrush = new PathGradientBrush(points);
e.Graphics.FillRectangle(pgbrush, trect);
e.Graphics.DrawRectangle(new Pen(Color.FromArgb(222, 252, 249), 1), trect);
e.Graphics.DrawString("This is test Font", new Font("宋体", 12), fontbrush, new Point(pt.X, pt.Y + 150));


7. 看看编译后的效果图(从上至下按照上面的顺序进行排列)



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值