這個範例會讓表單呈現橢圓形的形狀,且該形狀會隨著表單重設大小。
範例
protected:
virtual void OnPaint(
System::Windows::Forms::PaintEventArgs^ e) override
{
System::Drawing::Drawing2D::GraphicsPath^ shape =
gcnew System::Drawing::Drawing2D::GraphicsPath();
shape->AddEllipse(0, 0, this->Width, this->Height);
this->Region = gcnew System::Drawing::Region(shape);
}
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
System.Drawing.Drawing2D.GraphicsPath shape = new System.Drawing.Drawing2D.GraphicsPath();
shape.AddEllipse(0, 0, this.Width, this.Height);
this.Region = new System.Drawing.Region(shape);
}
Protected Overrides Sub OnPaint( _
ByVal e As System.Windows.Forms.PaintEventArgs)
Dim shape As New System.Drawing.Drawing2D.GraphicsPath
shape.AddEllipse(0, 0, Me.Width, Me.Height)
Me.Region = New System.Drawing.Region(shape)
End Sub
編譯程式碼
這個範例需要:
- System.Windows.Forms 和 System.Drawing 命名空間的參考。
本範例會覆寫 OnPaint 方法來變更表單的形狀。 若要使用此程式碼,請複製方法宣告,以及方法內的繪圖程式碼。