您的位置:首页 > 编程语言 > C#

C# 绘图2 画刷Brush

2017-02-13 08:57 197 查看
画刷
以画一个椭圆为例:

Point startPoint = new Point(10, 10);
Point endPoint = new Point(200, 80);
Graphics g = this.CreateGraphics();
SolidBrush brush = new SolidBrush(Color.Red);
g.FillEllipse(brush,startPoint.X,startPoint.Y,endPoint.X,endPoint.Y);
g.Dispose();


上边代码定义了两个点,startPoint和endPoint,并定义了坐标,之后定义了绘画的地方g,定义画刷brush,并以两个点框出一个矩形,在此矩形中画一个红色填充的椭圆,并释放g的资源

Brush类的派生类:



改变画刷:

比如定义了一个 Brush brush = new SolidBrush(Color.Red);

使其变成实心画刷:brush = new SolidBrush(Color.Green);

使其变成纹理画刷:首先要用imageList添加一张图片,然后brush = new TextureBrush( imageList1.Images[0]);

使其变成渐变画刷:加那边需要用到System.Drawing.Drawing2D;命名空间,添加之后,可以添加如下代码:

Point startPoint = new Point(80,70);

Point endPoint = new Point(310,70);

brush = new LinearGradientBrush(startPoint,endPoint,Color.Red,Color.Yellow);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: