HOW TO:在 Windows Form 上繪製實心橢圓形
這個範例會在表單上繪製實心橢圓形。
範例
Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.FillEllipse(myBrush, New Rectangle(0, 0, 200, 300))
myBrush.Dispose()
formGraphics.Dispose()
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(myBrush, new Rectangle(0, 0, 200, 300));
myBrush.Dispose();
formGraphics.Dispose();
System::Drawing::SolidBrush^ myBrush =
gcnew System::Drawing::SolidBrush(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->FillEllipse(myBrush, Rectangle(0, 0, 200, 300));
delete myBrush;
delete formGraphics;
編譯程式碼
您不能在 Load 事件處理常式中呼叫這個方法。 如果表單被重新調整或被另一表單遮住,將不會重新繪製表單的內容。 若要自動重新繪製內容,您應覆寫 OnPaint 方法。
穩固程式設計
對任何消耗系統資源的物件 (例如 Brush 和 Graphics 物件),您應一律呼叫 Dispose。