简体   繁体   English

如何使用图形对象的clear函数(需要color参数)来清除表单的图形?

[英]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.

相关问题 如何在不清晰的情况下绘制当前 Graphics 对象? - How can I draw the current Graphics object without clear? 在绘制另一个字母之前,如何清除图形? - How can I clear the Graphics before drawing another letter? 如何在C#中清除面板的图形? - How to clear panel's graphics in c#? 如何将单选按钮的功能(一个按钮单击,其他按钮自动清除)用于其他控件 - How do I use a radiobutton's function (one button click, the others clear automatically) to other controls 如何清除整个表单客户端,或者正确的方法是调用控制器并在那里清除模型? - How can I clear the entire form client side or would the proper way be to call the controller and clear the model there? 如何清除MDI子级的所有表单控件? - How can I clear all form controls of an MDI child? 如何清除 LINQ 查询、windows 表格? - How can I Clear LINQ query, windows form? 如何清除文本框? - How can I clear a TextBox? 如何清除.NET的反射缓存? - How can I clear .NET's reflection cache? 如何设置透明位图图像?设置属性Graphics.clear(color.Transparent)时会显示黑色背景。) - How to Creating Transparent Bitmap Image?It gives black background when i set property Graphics.clear(color.Transparent ).)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM