當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。