共用方式為


HOW TO:在 Windows Form 上繪製實心矩形

更新:2007 年 11 月

這個範例示範如何在表單上繪製實心矩形。

範例

System.Drawing.SolidBrush brush1 = 
    new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics = this.CreateGraphics();
formGraphics.FillRectangle(brush1, new System.Drawing.Rectangle(0,0,200,300));
brush1.Dispose();
formGraphics.Dispose();

編譯程式碼

這個範例需要:

  • 具有名為 formGraphics 之表單的 Windows Form 應用程式專案。

程式碼必須在 Form 類別的範圍內。此表單的執行個體是以 this 所表示。

穩固程式設計

針對任何會消耗系統資源的物件 (例如 BrushGraphics 物件),您應一律呼叫 Dispose

請參閱

概念

在 Visual C# 中設計使用者介面

其他資源

繪製文字和圖形

Visual C# 導覽