ITPub博客

首页 > 应用开发 > IT综合 > 浅析C#中图形编程之三(转)

浅析C#中图形编程之三(转)

原创 IT综合 作者:hphubei 时间:2007-07-09 23:17:08 0 删除 编辑
使用画刷对象:
   画刷对象是用特定的颜色、模式或是图像来填充一块区域的。总共有四种类型的画刷:SolidBrush(默认的画刷)、HatchBrush、GradientBrush以及TexturedBrush。下面,我们分别给出实例来进行介绍。

   1、运用SolidBrush:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

public class Solidbru:Form {
public Solidbru() {
this.Text = "运用SolidBrush示例";
this.Paint += new PaintEventHandler(Fill_Graph);
}


public void Fill_Graph(object sender,PaintEventArgs e) {
Graphics g = e.Graphics;
//创建一把SolidBrush并用它来填充一个矩形区域
SolidBrush sb = new SolidBrush(Color.Pink);
g.FillRectangle(sb,50,50,150,150);

}


public static void Main() {
Application.Run(new Solidbru());
}

}


   2、运用HatchBrush:

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;
public class Hatchbru:Form {
public Hatchbru() {
this.Text = "运用HatchBrush示例";
this.Paint += new PaintEventHandler(Fill_Graph);
}

public void Fill_Graph(object sender,PaintEventArgs e) {
Graphics g = e.Graphics;
//创建一把HatchBrush并用它来填充一个矩形区域
/*该画刷的HatchStyle有DiagonalCross、
ForwardDiagonal、Horizontal、 Vertical、 Solid等不同风格 */
HatchStyle hs = HatchStyle.Cross;
HatchBrush sb = new HatchBrush(hs,Color.Blue,Color.Red);
g.FillRectangle(sb,50,50,150,150);
}


public static void Main() {
Application.Run(new Hatchbru());
}

}
[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/79548/viewspace-925520/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
  • 博文量
    181
  • 访问量
    274750