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);
}
}
}
输出:
参考:
相关用法
- C# MathF.Tan()用法及代码示例
- C# MathF.Abs()用法及代码示例
- C# MathF.Log()用法及代码示例
- C# MathF.Pow()用法及代码示例
- C# MathF.Cos()用法及代码示例
- C# MathF.Exp()用法及代码示例
- C# MathF.Sin()用法及代码示例
- C# MathF.Max()用法及代码示例
- C# MathF.Min()用法及代码示例
- C# SByte.GetHashCode用法及代码示例
- C# SByte.CompareTo()用法及代码示例
- C# Stack.ToString()用法及代码示例
- C# SByte.Equals用法及代码示例
- C# UInt16.GetHashCode用法及代码示例
- C# UInt32.GetHashCode用法及代码示例
注:本文由纯净天空筛选整理自ShivamChauhan5大神的英文原创作品 Graphics.Clear() Method in C# with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。