还原C#的winform背景色 [英] Restore c# winform backcolor

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

问题描述

我有我改变背景颜色为 Col​​or.Yellow 单击时它的winform的按钮。当它再次点击我想把它恢复到原来的默认外观。

I have a button on a winform 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

新的背景不具有相同的阴影,因为它的点击之前本来。按钮原本有一个背景,这不是纯色但2略有不同的灰色色调。最终的颜色最终被灰色坚实的阴影。

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 2 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.

编辑:新增Sceenshot

Added Sceenshot

推荐答案

试试这个:

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

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

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