Share via


方法: 成型された Windows フォームを作成する

この例では、フォームを楕円形に成型して、そのフォームのサイズを変更します。

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

コードのコンパイル

この例で必要な要素は次のとおりです。

この例では、フォームの形状を変更する OnPaint メソッドをオーバーライドします。 このコードを使用するには、メソッド宣言に加えて、メソッド内の描画コードをコピーします。

関連項目