Condividi tramite


Procedura: creare un Windows Form con una forma

Nell'esempio riportato di seguito viene attribuita al form una forma ellittica che viene ridimensionata con il form.

Esempio

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

Compilazione del codice

L'esempio presenta i seguenti requisiti:

Nell'esempio viene eseguito l'override del metodo OnPaint per modificare la forma del form. Per utilizzare questo codice, copiare la dichiarazione di metodo e il codice di disegno all'interno del metodo.

Vedere anche

Riferimenti

OnPaint

Region

System.Drawing

AddEllipse

Region

Altre risorse

Guida introduttiva alla programmazione grafica