简体   繁体   English

为什么禁用的按钮会改变颜色?

[英]Why are my disabled buttons changing color?

My problem is: When my application is opened, I disable all buttons (in form_Load) and their color changes to the color of the background. 我的问题是:打开应用程序时,我禁用了所有按钮(在form_Load中),并且它们的颜色更改为背景的颜色。 But then I do some action (like clicking on a button), and in this action I disable the buttons again. 但是随后我执行了一些操作(例如单击按钮),然后在此操作中再次禁用了按钮。

Now some of these buttons become GRAY and others become as the background. 现在,这些按钮中的一些变成了灰色,其他变成了背景。

Why is this? 为什么是这样? I don't want the the gray effect. 我不要灰色效果。 Normally when I disable the button at the beginning of the application, it becomes the color I expect, but when I try to disable them again this strange behavior appeared. 通常,当我在应用程序的开头禁用按钮时,它会变成我期望的颜色,但是当我再次尝试禁用它们时,就会出现这种奇怪的行为。 What to do? 该怎么办?

My code is like: 我的代码是这样的:

private void _btnDownload2PC_Click(object sender, EventArgs e)
{
    // do action 
    _btnDownloadToPC.Enabled=false; // its color became gray
    _btnDownloadToPhone.Enabled=false; // its color became like the 
                                       // background color and it can't 
                                       // be pressed 
} 

I figured out that the problem is when I use the button_MouseLeave() or button_MouseMove() functions. 我发现问题出在我使用button_MouseLeave()button_MouseMove()函数时。 For example: 例如:

private void _btnOneToCort_MouseLeave(object sender, EventArgs e)
{
    this._btnOneToCart.Image=global::MyProject.Properties.Resources.button3over;
}

but this doesn't make sense. 但这没有意义。 Why does this function change my button settings (I don't know what these are) When I use these function this strange behavior appears, but when I don't, everything goes right? 为什么此功能会更改我的按钮设置(我不知道这些是什么),当我使用这些功能时,会出现这种奇怪的行为,但是当我不这样做时,一切都会正常进行?

Why don't disable buttons in designer? 为什么不禁用设计器中的按钮? If not acceptable, do that in form constructor not Form_Load. 如果不可接受,请使用表单构造函数而不是Form_Load进行。

Also, how can you click on button if it's disabled? 另外,如果按钮被禁用,如何单击呢?

Are form color settings default? 表单颜色设置是否为默认设置? Have you changed windows theme color preferences? 您是否更改了Windows主题颜色的首选项?

You can programmatically access the color of a button. 您可以以编程方式访问按钮的颜色。 Set a breakpoint and do that to see if they really are changing. 设置一个断点,然后查看它们是否确实在更改。

My guess: the image that you are setting has a gray background that is different than the standard disabled color. 我的猜测:您所设置的图像的灰色背景不同于标准的禁用颜色。 You will need to edit the image and remove the background. 您将需要编辑图像并删除背景。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM