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()); }
} |
3、运用GradientBrush:
GradientBrush又可分为LinearGradientBrush和PathGradientBrush两种,从它们的名称我们可以知道前者是线性渐变的,而后者则是路径渐变的,因而能创造出更复杂和完美的效果。下面我就给大家分别举例:
1)、运用LinearGradientBrush:
using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D;
public class LinearGradientbru:Form { public LinearGradientbru() { this.Text = "运用LinearGradientBrush示例"; this.Paint += new PaintEventHandler(Fill_Graph); }
public void Fill_Graph(object sender,PaintEventArgs e) { Rectangle r = new Rectangle(500, 300, 100, 100); LinearGradientBrush lb = new LinearGradientBrush(r, Color.Red, Color.Yellow, LinearGradientMode.BackwardDiagonal); e.Graphics.FillRectangle(lb, r); }
public static void Main() { Application.Run(new LinearGradientbru()); } }
|
2)、运用PathGradientBrush:
using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D;
public class PathGradientbru:Form { public PathGradientbru() { this.Text = "运用PathGradientBrush示例"; this.Paint += new PaintEventHandler(Fill_Graph); }
public void Fill_Graph(object sender,PaintEventArgs e) { e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliased; e.Graphics.FillRectangle(backgroundBrush, ClientRectangle); e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(180, Color.White)), ClientRectangle);
//先设置好一个路径 GraphicsPath path = new GraphicsPath(new Point[] { new Point(40, 140), new Point(275, 200), new Point(105, 225), new Point(190, 300), new Point(50, 350), new Point(20, 180), }, new byte[] {
(byte)PathPointType.Start, (byte)PathPointType.Bezier, (byte)PathPointType.Bezier, (byte)PathPointType.Bezier, (byte)PathPointType.Line, (byte)PathPointType.Line, });
//创建一把PathGradientBrush
PathGradientBrush pgb = new PathGradientBrush(path);
//设置画刷的周围颜色
pgb.SurroundColors = new Color[] { Color.Green, Color.Yellow, Color.Red, Color.Blue, Color.Orange, Color.White,
};
//用画刷进行填充 e.Graphics.FillPath(pgb, path); }
public static void Main() { Application.Run(new PathGradientbru()); }
} | |