Clear Method

Graphics.Clear Method (Color)


Clears the entire drawing surface and fills it with the specified background color.

Namespace:   System.Drawing
Assembly:  System.Drawing (in System.Drawing.dll)

public void Clear(
	Color color


Type: System.Drawing.Color

Color structure that represents the background color of the drawing surface.

The Clear method clears the state of the graphics object and should not be called when the graphics object cannot be updated. 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.

The following code example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 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.

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft