如何:在 Windows 窗体上绘制实心椭圆
更新:2007 年 11 月
此示例在窗体上绘制实心椭圆。
示例
Dim myBrush As New System.Drawing.SolidBrush(System.Drawing.Color.Red)
Dim formGraphics As System.Drawing.Graphics
formGraphics = Me.CreateGraphics()
formGraphics.FillEllipse(myBrush, New Rectangle(0, 0, 200, 300))
myBrush.Dispose()
formGraphics.Dispose()
System.Drawing.SolidBrush myBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
System.Drawing.Graphics formGraphics;
formGraphics = this.CreateGraphics();
formGraphics.FillEllipse(myBrush, new Rectangle(0, 0, 200, 300));
myBrush.Dispose();
formGraphics.Dispose();
System::Drawing::SolidBrush^ myBrush =
gcnew System::Drawing::SolidBrush(System::Drawing::Color::Red);
System::Drawing::Graphics^ formGraphics;
formGraphics = this->CreateGraphics();
formGraphics->FillEllipse(myBrush, Rectangle(0, 0, 200, 300));
delete myBrush;
delete formGraphics;
编译代码
不能在 Load 事件处理程序中调用此方法。如果已调整该窗体的大小或者其他窗体遮蔽了该窗体,则不会重绘所绘制的内容。若要自动重绘内容,应该重写 OnPaint 方法。
可靠编程
对任何消耗系统资源的对象(如 Brush 和 Graphics 对象)都应调用 Dispose。