如何:在 Windows 窗体上绘制填充椭圆
本示例在窗体上绘制填充椭圆。
例
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;
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();
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()
编译代码
无法在 Load 事件处理程序中调用此方法。 如果窗体被调整大小或被另一个窗体遮盖,则不会重绘绘制的内容。 若要使您的内容自动重绘,应重写 OnPaint 方法。
可靠的编程
应始终对使用系统资源的任何对象(如 Brush 和 Graphics 对象)调用 Dispose。
另请参阅
- 在 Windows 窗体 中
图形和绘图 - 图形编程入门
- Alpha 叠加线条和填充
- 使用画笔填充形状