当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C# Graphics.Clear()用法及代码示例


Graphics.Clear(color)方法用于清除画布并使用指定的背景颜色对其进行绘制。

用法: public void Clear (System.Drawing.Color color);
参数:
color: Color identifier which contains RGB values, to colour the background of canvas.

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

输出:

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

输出:

参考:



相关用法


注:本文由纯净天空筛选整理自ShivamChauhan5大神的英文原创作品 Graphics.Clear() Method in C# with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。