Graphics.Clear() Method in C# with Examples
Graphics.Clear(color) Method is used to clear the canvas and paints it up with the specified background color.
Syntax: public void Clear (System.Drawing.Color color);
Parameter:
color: Color identifier which contains RGB values, to colour the background of canvas.
Example 1:
// C# snippet to print GeeksForGeeks using System; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; namespace GFG { class PrintableForm : Form { // Main Method public static void Main() { Application.Run(new PrintableForm()); } public PrintableForm() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs e) { Font font = new Font("Arial", 16); SolidBrush brush = new SolidBrush(Color.Black); PointF point = new PointF(10.0F, 10.0F); e.Graphics.DrawString("GeeksForGeeks", font, brush, point); } } } |
chevron_right
filter_none
Output:

Example 2:
// C# program to illustrate the Clear Method // C# snippet to print GeeksForGeeks using System; using System.Drawing; using System.Drawing.Printing; using System.Windows.Forms; namespace GFG { class PrintableForm : Form { // Main Method public static void Main() { Application.Run(new PrintableForm()); } public PrintableForm() { ResizeRedraw = true; } protected override void OnPaint(PaintEventArgs e) { e.Graphics.Clear(Color.Coral); } } } |
chevron_right
filter_none
Output:

Reference:
Recommended Posts:
- MathF.Min() Method in C# with Examples
- MathF.Pow() Method in C# with Examples
- MathF.Cos() Method in C# with Examples
- MathF.Max() Method in C# with Examples
- MathF.Abs() Method in C# with Examples
- MathF.Sin() Method in C# with Examples
- MathF.Exp() Method in C# with Examples
- MathF.Log() Method in C# with Examples
- MathF.Tan() Method in C# with Examples
- Int64.Equals Method in C# with Examples
- Int32.Equals Method in C# with Examples
- Int32.CompareTo Method in C# with Examples
- Int16.GetTypeCode Method in C# with Examples
- Double.CompareTo Method in C# with Examples
- Int32.GetTypeCode Method in C# with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



