在C#编程语言中,画刷是一个非常重要的概念,用于定义用于填充图形形状的对象。画刷可以是简单的圆形或椭圆形,也可以是复杂的多边形或封闭路径。本文将探讨画刷的定义、类型和用途。
画刷是一个抽象基类,用于表示用于填充图形形状的对象。在C#中,可以通过定义一个画刷类来实现画刷的功能。画刷类可以具有不同的属性和方法,例如填充颜色、形状、路径等。画刷类还可以继承其他画刷类,从而创建更高级的画刷对象。
画刷有多种类型,例如圆形画刷、椭圆形画刷、矩形画刷、多边形画刷和封闭路径画刷等。每种类型的画刷都具有不同的填充方式和路径属性。例如,圆形画刷只能用于填充圆形,而矩形画刷则可以用于填充矩形和其他矩形形状。多边形画刷则可以用于填充各种形状,包括三角形、四边形、五边形等。封闭路径画刷可以用于填充封闭路径,例如圆形、椭圆形、多边形和路径等。
纯色刷子
C#Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
SolidBrush brush=new SolidBrush(Color.DarkRed);//纯色刷
g.FillRectangle(brush, rect);//纯色刷
阴影刷
C#Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
HatchBrush brush=new HatchBrush(HatchStyle.Cross,Color.DarkRed);//阴影刷
g.FillRectangle(brush, rect);//阴影刷
纹理刷
C#Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
Bitmap bitmap = new Bitmap("./add.png");
TextureBrush brush = new TextureBrush(bitmap);//纹理刷
g.FillRectangle(brush, rect);
线性渐进刷
C#Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
LinearGradientBrush brush = new LinearGradientBrush(rect
, Color.DarkOrange, Color.Aquamarine, 45);
g.FillRectangle(brush, rect);
路径渐进画刷
C#Graphics g = e.Graphics;
Rectangle rect = this.ClientRectangle;
Point _Left1 = new Point(0, 0);
Point _Left2 = new Point(this.Width / 2, 0);
Point _Left3 = new Point(this.Width / 2, this.Height);
Point _Left4 = new Point(0, this.Height);
Point[] _Point = new Point[] { _Left1, _Left2, _Left3, _Left4 };
PathGradientBrush _SetBruhs = new PathGradientBrush(_Point, WrapMode.TileFlipXY);
_SetBruhs.CenterPoint = new PointF(0, 0);
_SetBruhs.FocusScales = new PointF(0, this.Height);
_SetBruhs.CenterColor = Color.Red;
_SetBruhs.SurroundColors = new Color[] { Color.Yellow };
e.Graphics.FillRectangle(_SetBruhs, rect);
本文作者:rick
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!