共用方式為


HOW TO:建立具圖案的 Windows Form

這個範例使表單具有橢圓形狀,而該圖案會隨表單調整大小。

範例

 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
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:
    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);
    }

編譯程式碼

這項範例需要:

這個範例覆寫 OnPaint 方法來變更表單圖案。 若要使用這個程式碼,請複製方法宣告及方法內部的繪圖程式碼。

請參閱

參考

OnPaint

Region

System.Drawing

AddEllipse

Region

其他資源

圖形程式設計入門