GDI+ = Graphics Device Interface Plus,圖形裝置介面增強版。提供豐富 2D 圖形圖像處理功能;3D 用 DirectX。
| 類別 | 用途 |
|---|---|
| Graphics | 畫布/繪圖面,所有繪圖操作的核心 |
| Bitmap | 位圖,像素級圖像操作 |
| Pen | 畫筆,繪製線條、輪廓 |
| Brush | 畫刷,填充封閉區域 |
| Font | 字體,文字繪製 |
| Color | 顏色結構 |
| Image/Icon | 圖像/圖示載入繪製 |
e.Graphics(推薦,自動雙緩衝、重繪安全)
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics; // 方式 1:取得畫布
Pen p = new Pen(Color.Blue, 2); // 藍色、寬度 2 的畫筆
// 直線:起點 (10,10) 終點 (100,100)
g.DrawLine(p, 10, 10, 100, 100);
// 矩形:左上 (10,10) 寬 100 高 100
g.DrawRectangle(p, 10, 10, 100, 100);
// 橢圓:外接矩形左上 (10,10) 寬 100 高 100
g.DrawEllipse(p, 10, 10, 100, 100);
}

Pen、Brush、Graphics、Bitmap 等實作 IDisposableusing 區塊e.Graphics **由系統管理,勿手動 Dispose**