跟着 伍逸 老師學GDI+
最近在看伍逸 老師著的《C# 二維三維圖形繪製工程實例寶典》,感覺這本書太經典了,心想一定要堅持把這本書看完,爲了能勉勵自己,特註冊次博客。在此對伍逸老師表示由衷的感謝。
2.Brush的學習
2.1 SolidBrush: 實心畫刷
2.2 HatchBrush: 陰影畫刷
2.3 LinerGradientBrush: 線性漸變畫刷
用法如下:(與書上同)
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- namespace _002Brush
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Paint(object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- Brush brSolid = new SolidBrush(Color.Blue);
- Brush brHatch = new HatchBrush(HatchStyle.HorizontalBrick, Color.Red, Color.Yellow);
- Brush brGradient = new LinearGradientBrush(new Rectangle(0,0,200,200),Color.Black,Color.LightGray,45,false);
- g.FillRectangle(brGradient,10,10,200,200);
- g.FillEllipse(brHatch,200,200,150,190);
- g.FillPie(brSolid,0,0,300,300,285,75);
- }
- }
- }
運行結果如下: