BDeveloper
BDeveloper

Reputation: 1287

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

Upvotes: 1

Views: 2945

Answers (2)

colithium
colithium

Reputation: 10327

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.

Upvotes: 1

abatishchev
abatishchev

Reputation: 100258

Why don't disable buttons in designer? If not acceptable, do that in form constructor not 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?

Upvotes: 0

Related Questions