还原C#Windows窗体背景色 [英] Restore C# Windows Forms backcolor

查看:76
本文介绍了还原C#Windows窗体背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows Forms表单上有一个按钮,单击该按钮后,背景颜色会更改为 Color.Yellow .再次单击时,我想将其还原为原始的默认外观.

I have a button on a Windows Forms form for which I change the background color to Color.Yellow when it's clicked. When it's clicked again I want to restore it to the original default appearance.

默认背景色为 SystemColor.Control .

第一次单击按钮时,我唯一要更改的就是

When the button is clicked the first time the only thing I change is the

btn.Text = "ABC";
btn.BackColor = Color.Yellow;

当我再次单击它时

btn.BackColor = SystemColors.Control

新背景的阴影与单击之前的阴影不同.该按钮最初的背景不是纯色,而是两个略有不同的灰色阴影.最终的颜色最终变为纯灰色.

The new background does not have the same shading as it originally did before any clicks. The button originally had a background that was not a solid color, but was two slightly different shades of grey. The final color ends up being a solid shade of grey.

我正在Windows 7计算机上对此进行测试.

I'm testing this on a Windows 7 machine.

屏幕截图:

推荐答案

尝试一下:

if (button1.BackColor == Color.Yellow)
{
    button1.BackColor = SystemColors.Control;
    button1.UseVisualStyleBackColor = true;
}
else
{
    button1.BackColor = Color.Yellow;
}

这篇关于还原C#Windows窗体背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆