如何:创建特定形状的 Windows 窗体
更新:2007 年 11 月
此示例向窗体提供随该窗体一起调整大小的椭圆形状。
示例
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);
}
编译代码
此示例需要:
- 对 System.Windows.Forms 和 System.Drawing 命名空间的引用。
该示例重写 OnPaint 方法以更改窗体的形状。若要使用此代码,请将方法声明以及绘图代码复制到该方法中。