跟着 伍逸 老师学GDI+

    最近在看伍逸 老师著的《C# 二维三维图形绘制工程实例宝典》,感觉这本书太经典了,心想一定要坚持把这本书看完,为了能勉励自己,特注册次博客。在此对伍逸老师表示由衷的感谢。

2.Brush的学习

  2.1 SolidBrush: 实心画刷

  2.2 HatchBrush: 阴影画刷

  2.3 LinerGradientBrush: 线性渐变画刷

 用法如下:(与书上同)

 
  
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using System.Drawing.Drawing2D;  
  10. namespace _002Brush  
  11. {  
  12.     public partial class Form1 : Form  
  13.     {  
  14.         public Form1()  
  15.         {  
  16.             InitializeComponent();  
  17.         }  
  18.  
  19.         private void Form1_Paint(object sender, PaintEventArgs e)  
  20.         {  
  21.             Graphics g = e.Graphics;  
  22.             Brush brSolid = new SolidBrush(Color.Blue);  
  23.             Brush brHatch = new HatchBrush(HatchStyle.HorizontalBrick, Color.Red, Color.Yellow);  
  24.             Brush brGradient = new LinearGradientBrush(new Rectangle(0,0,200,200),Color.Black,Color.LightGray,45,false);  
  25.             g.FillRectangle(brGradient,10,10,200,200);  
  26.             g.FillEllipse(brHatch,200,200,150,190);  
  27.             g.FillPie(brSolid,0,0,300,300,285,75);  
  28.         }  
  29.  
  30.     }  

运行结果如下: