SolidBrush继承自Brush,表示单色的笔刷。
Brushes 类则继承自System.Object。它提供了一些标准颜色的画笔,包含静态的只读属性,这些属性返回由属性名指示的颜色的 Brush 对象。通常不必显式处置由此类中的属性返回的画笔,除非该画笔用于构造新画笔。因此,没有必要创建Brushes 类的实例
可以这么看Brush brush = Brushes.Green 和 Brush brush = new SolidBrush(Color.Green) 是等效的。只不过后者一般是需要 brush.Dispose() 的,前者不需要。
还有其他的继承自 Brush 的类
System.Drawing.Drawing2D.HatchBrush(阴影、前景色和背景色定义的矩形笔刷)
System.Drawing.Drawing2D.LinearGradientBrush(线性渐变笔刷)
System.Drawing.Drawing2D.PathGradientBrush(用渐变填充 GraphicsPath 对象的内部的笔刷)
System.Drawing.TextureBrush(用图像来填充形状的内部的笔刷)

//实现功能:用Brush画图

//   1)创建的渐变色Brush(LinearGradientBrush,用完后应及时Dispose.)

//   2)用Brushes绘图.(无须创建Brush)

//  3)创建自定义颜色的SolidBrush

//   4)画矩形,椭圆,扇形,多边形

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;//另添加

namespace myDrawBrushA

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

SetStyle(ControlStyles.Opaque, true);//本例由于在OnPaint()中将客户区先涂上白色后再绘画,所以此句可有可无。

}

protected override void OnPaint(PaintEventArgs e)

{

//base.OnPaint(e);

Graphics g = e.Graphics;

g.FillRectangle(Brushes.White, ClientRectangle);//全部客户区涂上白色

g.FillRectangle(Brushes.Red, new Rectangle(20, 20, 80, 80));//红色正方形

//以下创建一个Brush画渐变色正方形

Brush linearGradientBrush = new LinearGradientBrush(

new Rectangle(20, 110, 80,80), Color.Blue, Color.White,45);//创建渐变色brush,渐变方向:45-左上至右下;90-向下:......

g.FillRectangle(linearGradientBrush, new Rectangle(20, 110, 80, 80));//画渐变色正方形

linearGradientBrush.Dispose();//注意及时删除渐变色brush

//以下用Brushes(不要创建Brush)

g.FillEllipse(Brushes.Aquamarine, new Rectangle(110,20, 100, 60));//椭圆(前两个参数是外接矩形左上角坐标)

g.FillPie(Brushes.Chartreuse, new Rectangle(110, 110, 80, 80), 90, 270);//扇形(207为圆心角度数,90为扇形旋转的角度

g.FillPolygon(Brushes.BlueViolet, new Point[]{

new Point(220,10),

new Point(300,10),

new Point(250,40),

new Point(350,80),

new Point(230,100)

});       //多边形

//以下用创建自定义颜色的SolidBrush画圆

SolidBrush trnsRedBrush = new SolidBrush(Color.FromArgb(120, 255, 0, 0));

SolidBrush trnsGreenBrush = new SolidBrush(Color.FromArgb(120, 0, 255, 0));

SolidBrush trnsBlueBrush = new SolidBrush(Color.FromArgb(120, 0, 0, 255));

// Base and height of the triangle that is used to position the

// circles. Each vertex of the triangle is at the center of one of the

// 3 circles. The base is equal to the diameter of the circles.

float triBase = 50;

float triHeight = (float)Math.Sqrt(3 * (triBase * triBase) /4);

// Coordinates of first circle's bounding rectangle.

float x1 = 200;

float y1 = 100;

// Fill 3 over-lapping circles. Each circle is a different color.

g.FillEllipse(trnsRedBrush, x1, y1, 2 * triHeight, 2 * triHeight);

g.FillEllipse(trnsGreenBrush, x1 + triBase / 2, y1 + triHeight,

2 * triHeight, 2 * triHeight);

g.FillEllipse(trnsBlueBrush, x1 + triBase, y1, 2 * triHeight, 2 * triHeight);

}

}

}

画图------Brush的更多相关文章

  1. Graphics 导出图片使用【这个主要是画图类图的使用,记录一下】

    /// <summary> /// 导出信令流程矢量图 /// </summary> /// <param name="signalFlowInfos" ...

  2. html5之canvas画图

    导航 前言 基本知识 绘制矩形 清除矩形区域 圆弧 路径 绘制线段 绘制贝塞尔曲线 线性渐变 径向渐变(发散) 图形变形(平移.旋转.缩放) 矩阵变换(图形变形的机制) 图形组合 给图形绘制阴影 绘制 ...

  3. c#代码画图

    说明:此示例代码在我做的一个项目中  不过还是可以学习一下 一:直角坐标系显示数据 先看效果图:

  4. 与众不同 windows phone (17) - Graphic and Animation(画图和动画)

    原文:与众不同 windows phone (17) - Graphic and Animation(画图和动画) [索引页][源码下载] 与众不同 windows phone (17) - Grap ...

  5. C#后台画图保存为ipg/png的文件

    public void Exec1()        { string imgurl = @"http://api.senwoo.com/Content/HeadPortrait/" ...

  6. AutoCAD 凸度(bulge)的概念及使用WPF函数画图

    前言  凸度(bulge)是AutoCAD 中一个非常重要的概念,凸度控制着两点之间弧度大小,弧度的方向.各种复杂的图像有可能就是成百上千的弧线组成的.从AutoCAD中导出的数据也有该值,一般的形式 ...

  7. WPF 使用 Direct2D1 画图入门

    本文来告诉大家如何在 WPF 使用 D2D 画图. 本文是一个系列 WPF 使用 Direct2D1 画图入门 WPF 使用 Direct2D1 画图 绘制基本图形 WPF 使用 SharpDX WP ...

  8. WPF 使用 Direct2D1 画图 绘制基本图形

    本文来告诉大家如何在 Direct2D1 绘制基本图形,包括线段.矩形.椭圆 本文是一个系列 WPF 使用 Direct2D1 画图入门 WPF 使用 Direct2D1 画图 绘制基本图形 本文的组 ...

  9. 【转】C#中Graphics的画图代码

    C#中Graphics的画图代码[转] 架上图片了你就可以在画板上涂改了啊 我要写多几个字上去string str = "Baidu"; //写什么字?Font font = Fo ...

随机推荐

  1. VS2010水晶报表的添加与使用

    最近在学习VS2010水晶报表,发现原先安装的VS2010旗舰版没有 Crystal Report Viewer 控件,网上搜索一下发现要安装一个插件----CRforVS_13_0, 于是下载安装: ...

  2. mac 上的版本控制工具SmartSVN9.0.4(破解版)

    附带上破解版安装说明: 1.在MAC上选中SmartSVN.dmg,右键->打开2.双击syntevo_keygen.jar 如果没有安装java会自动提示安装的3.输入Name Email(随 ...

  3. K最近邻算法

    K最近邻(K-Nearest-Neighbour,KNN)算法是机器学习里简单易掌握的一个算法.通过你的邻居判断你的类型,“近朱者赤,近墨者黑”表达了K近邻的算法思想. 一.算法描述: 1.1 KNN ...

  4. 1011. World Cup Betting (20)(最大值)

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  5. Printer Queue

    Description The only printer in the computer science students' union is experiencing an extremely he ...

  6. Hive[5] HiveQL 数据操作

    5.1 向管理表中装载数据   Hive 没有行级别的数据插入更新和删除操作,那么往表中装载数据的唯一途径就是使用一种“大量”的数据装载操作,或者通过其他方式仅仅将文件写入到正确的目录下:   LOA ...

  7. git操作技巧(转载)

    转载自:https://segmentfault.com/q/1010000000181403 git支持很多种工作流程,我们采用的一般是这样,远程创建一个主分支,本地每人创建功能分支,日常工作流程如 ...

  8. 【BZOJ 1084】[SCOI2005]最大子矩阵

    Description 这里有一个n*m的矩阵,请你选出其中k个子矩阵,使得这个k个子矩阵分值之和最大.注意:选出的k个子矩阵不能相互重叠. Input 第一行为n,m,k(1≤n≤100,1≤m≤2 ...

  9. 信息化的“五观”与“N为”

    系统观:联系的总体的看 生产力工具观:人与工具关系 马克思政治经济学 辨证观:发展的看 技术观:第一生产力  改变生产生活(生存)方式 信息论观:“人”联网 控制论 工程观:群体合作的智力游戏论

  10. HighCharts 根据spline-plot-bands图,定制自己的图(区间里显示多个数据)

    公司项目里有这样一个需求,根据数据绘图,但是数据很多,不可能每个点每个点的去画,这样显示的数据太密集非常的难看(更显得技术不专业),如图: 所以我和项目经理商量如何显示这个图形,按照他的意思是,按照范 ...