[英]How can I use a graphic object's clear function(which requires a color argument) to clear the graphics of a form?
How can I use a graphic object's clear function(which requires a color argument) to clear the graphics of a form? 如何使用图形对象的clear函数(需要color参数)来清除表单的图形?
Using WFA 使用WFA
public partial class Form1 : Form
{
Graphics gr;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
gr = this.CreateGraphics();
gr.DrawLine(new Pen(Color.Red), 0, 0, 500, 500);
//gr.Clear(); // ERROR IT NEEDS AN ARGUMENT BUT WHAT?
}
}
}
gr.Clear() needs an argument, but what colour? gr.Clear()需要一个参数,但是什么颜色?
I tried MessageBox.Show(this.BackColor.ToString());
我尝试了MessageBox.Show(this.BackColor.ToString());
so as to see the color of the form. 以便查看表格的颜色。 But it just displays "Color [Control]"
which doesn't tell me anything. 但是它只显示"Color [Control]"
,它什么也没告诉我。
I tried gr.Clear(Color.Gray)
but that's not the correct colour, it's not the color of the default background of the form. 我尝试了gr.Clear(Color.Gray)
但这不是正确的颜色,它不是表单默认背景的颜色。
Since you are creating the control, I assume you should know what the color is. 由于您正在创建控件,因此我假设您应该知道颜色是什么。 If you want the default control background color, just use gr.Clear(BackColor)
There is no need to see what color it is, it just is the color you assigned to it or the system default. 如果要使用默认的控件背景色,只需使用gr.Clear(BackColor)
无需查看它是什么颜色,它只是您分配给它的颜色或系统默认值。
For transparent controls you would use Color.Transparent, but usually controls are not needed to be transparent. 对于透明控件,您可以使用Color.Transparent,但是通常不需要透明控件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.