C#编程-130:Brush的五个继承类

C#编程-130:Brush的五个继承类_第1张图片

Brush笔刷类,可以用颜色和图像填充图形,是 抽象类,不可以实例化。

实例:
1、SolidBrushTest

C#编程-130:Brush的五个继承类_第2张图片

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4.  
  5. namespace SolidBrushTest
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.  
  14.         private void Form1_Paint(object sender, PaintEventArgs e)
  15.         {
  16.             Graphics g = e.Graphics;
  17.             Brush brush = new SolidBrush(Color.Orange);
  18.             g.FillEllipse(brush, 10, 10, 200, 120);
  19.             g.Dispose();
  20.  
  21.         }
  22.     }
  23. }

2、 TextureBrushTest

C#编程-130:Brush的五个继承类_第3张图片

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.IO;
  5. namespace TextureBrushTest
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.         private void Form1_Paint(object sender, PaintEventArgs e)
  14.         {
  15.             string path = @"D:\CS\GDIPlusTest\TextureBrushTest\img\微信图片_20170817213231.jpg";
  16.             Graphics g=e.Graphics;
  17.             if (File.Exists(path))
  18.             {
  19.                 Bitmap map = new Bitmap(path);
  20.                 Brush brush = new TextureBrush(map);
  21.                 g.FillEllipse(brush, 10, 10, 500, 500);
  22.                 brush.Dispose();
  23.             }
  24.             else
  25.             {
  26.                 MessageBox.Show("image is not exists");
  27.             }
  28.             g.Dispose();
  29.         }
  30.     }
  31. }

3、LinearGradientBrushTest

C#编程-130:Brush的五个继承类_第4张图片

  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Drawing.Drawing2D;
  5. namespace LinearGradientBrushTest
  6. {
  7.     public partial class Form1 : Form
  8.     {
  9.         public Form1()
  10.         {
  11.             InitializeComponent();
  12.         }
  13.             private void Form1_Paint(object sender, PaintEventArgs e)
  14.         {
  15.             Graphics g = e.Graphics;
  16.             LinearGradientBrush lgb = new LinearGradientBrush(new Point(10,10),new Point(290,90),Color.White,Color.FromArgb(255,0,0,0));
  17.             g.FillEllipse(lgb,10,10,280,120);
  18.             lgb.Dispose();
  19.             g.Dispose();
  20.         }
  21.     }
  22. }

4、 PathGradientBrushTest

C#编程-130:Brush的五个继承类_第5张图片

  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. using System.Drawing.Drawing2D;
  4. namespace PathGradientBrushTest
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void Form1_Paint(object sender, PaintEventArgs e)
  14.         {
  15.             //绘画路径
  16.             GraphicsPath gp = new GraphicsPath();
  17.             gp.AddEllipse(0,80,240,120);
  18.  
  19.             //路径渐变画刷
  20.             PathGradientBrush pgb = new PathGradientBrush(gp);
  21.             pgb.CenterColor = Color.Orange;
  22.             Color[] colors = { Color.FromArgb(255,0,255,0)};
  23.             pgb.SurroundColors = colors;
  24.  
  25.             //绘制椭圆
  26.             e.Graphics.FillEllipse(pgb,0,80,240,120);
  27.             pgb.Dispose();
  28.         }
  29.     }
  30. }

5、 HatchBrushTest
C#编程-130:Brush的五个继承类_第6张图片

  1. using System.Drawing;
  2. using System.Windows.Forms;
  3. using System.Drawing.Drawing2D;
  4. namespace HatchBrushTest
  5. {
  6.     public partial class Form1 : Form
  7.     {
  8.         public Form1()
  9.         {
  10.             InitializeComponent();
  11.         }
  12.  
  13.         private void Form1_Paint(object sender, PaintEventArgs e)
  14.         {
  15.             HatchBrush hatchBrush = new HatchBrush(HatchStyle.HorizontalBrick,Color.Red,Color.Yellow);
  16.             e.Graphics.FillEllipse(hatchBrush,0,80,240,120);
  17.             hatchBrush.Dispose();
  18.         }
  19.     }
  20. }

你可能感兴趣的:(C#编程-130:Brush的五个继承类)