C#编程-130:Brush的五个继承类
2024-06-25 09:50:39 阅读次数:26
编程开发
Brush笔刷类,可以用颜色和图像填充图形,是 抽象类,不可以实例化。
实例:
1、SolidBrushTest
- using System;
- using System.Drawing;
- using System.Windows.Forms;
-
- namespace SolidBrushTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- Brush brush = new SolidBrush(Color.Orange);
- g.FillEllipse(brush, 10, 10, 200, 120);
- g.Dispose();
-
- }
- }
- }
2、 TextureBrushTest
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.IO;
- namespace TextureBrushTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- string path = @"D:\CS\GDIPlusTest\TextureBrushTest\img\微信图片_20170817213231.jpg";
- Graphics g=e.Graphics;
- if (File.Exists(path))
- {
- Bitmap map = new Bitmap(path);
- Brush brush = new TextureBrush(map);
- g.FillEllipse(brush, 10, 10, 500, 500);
- brush.Dispose();
- }
- else
- {
- MessageBox.Show("image is not exists");
- }
- g.Dispose();
- }
- }
- }
3、LinearGradientBrushTest
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace LinearGradientBrushTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- LinearGradientBrush lgb = new LinearGradientBrush(new Point(10,10),new Point(290,90),Color.White,Color.FromArgb(255,0,0,0));
- g.FillEllipse(lgb,10,10,280,120);
- lgb.Dispose();
- g.Dispose();
- }
- }
- }
4、PathGradientBrushTest
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace PathGradientBrushTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- //绘画路径
- GraphicsPath gp = new GraphicsPath();
- gp.AddEllipse(0,80,240,120);
-
- //路径渐变画刷
- PathGradientBrush pgb = new PathGradientBrush(gp);
- pgb.CenterColor = Color.Orange;
- Color[] colors = { Color.FromArgb(255,0,255,0)};
- pgb.SurroundColors = colors;
-
- //绘制椭圆
- e.Graphics.FillEllipse(pgb,0,80,240,120);
- pgb.Dispose();
- }
- }
- }
5、HatchBrushTest
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace HatchBrushTest
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- HatchBrush hatchBrush = new HatchBrush(HatchStyle.HorizontalBrick,Color.Red,Color.Yellow);
- e.Graphics.FillEllipse(hatchBrush,0,80,240,120);
- hatchBrush.Dispose();
- }
- }
- }
版权声明:本文内容来自第三方投稿或授权转载,原文地址:https://blog.51cto.com/mouday/3046980,作者:彭世瑜,版权归原作者所有。本网站转在其作品的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如因作品内容、版权等问题需要同本网站联系,请发邮件至ctyunbbs@chinatelecom.cn沟通。
上一篇:Python编程:calendar日历模块入门
下一篇:C#编程-99:索引器实例QQ状态