Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Graphics.Clear() Method in C# with Examples

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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);
    }
}
}

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);
    }
}
}

Output:

Reference:


My Personal Notes arrow_drop_up
Last Updated : 04 Apr, 2019
Like Article
Save Article
Similar Reads