背景:
阅读新闻

浅析C#中图形编程

[日期:2003-07-11] 来源:天极网  作者:王凯明 [字体: ]


  使用画刷对象:

  画刷对象是用特定的颜色、模式或是图像来填充一块区域的。总共有四种类型的画刷: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());
}

}


收藏 推荐 打印 | 录入:木鸟 | 阅读:
相关新闻      
本文评论   [发表评论]   全部评论 (0)
热门评论