Graphics.Clear(Color) 方法

定义

清除整个绘图面并以指定背景色填充。Clears the entire drawing surface and fills it with the specified background color.

public:
 void Clear(System::Drawing::Color color);
public void Clear (System.Drawing.Color color);
member this.Clear : System.Drawing.Color -> unit
Public Sub Clear (color As Color)

参数

color
Color

Color 结构,它表示绘图面的背景色。Color structure that represents the background color of the drawing surface.

示例

下面的代码示例旨在与 Windows 窗体一起使用,并且它需要作为 PaintEventArgs e Paint 事件处理程序的参数。The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 该代码将清除的绘图图面 Graphics ,并将背景色设置为系统定义的青色颜色。The code clears the drawing surface of the Graphics and sets the background color to the system-defined teal color.

private:
   void ClearColor( PaintEventArgs^ e )
   {
      // Clear screen with teal background.
      e->Graphics->Clear( Color::Teal );
   }
private void ClearColor(PaintEventArgs e)
{
    // Clear screen with teal background.
    e.Graphics.Clear(Color.Teal);
}
Private Sub ClearColor(ByVal e As PaintEventArgs)

    ' Clear screen with teal background.
    e.Graphics.Clear(Color.Teal)
End Sub

注解

Clear方法清除图形对象的状态,不应在无法更新图形对象时调用。The Clear method clears the state of the graphics object and should not be called when the graphics object cannot be updated. 例如,如果在 Clear 终端服务器会话中的安全桌面上调用方法,则 ExternalException 可能会发生,使 Graphics 对象处于不一致状态。For example, if the Clear method is called on a secure desktop in a terminal server session, an ExternalException may occur, leaving the Graphics object in an inconsistent state.

适用于