Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winforms button: Does Visible = false imply Enabled = false?

Simple question: I have a WinForms button, and I want to make it both (conditionally) invisible and disabled (to be sure that if someone clicks in the space where the invisible button lives, it won't activate it.) Does button.Visible = false also imply button.Enabled = false, or do I need to set/reset both properties at the appropriate time?

like image 616
Dave Hanna Avatar asked Sep 15 '09 15:09

Dave Hanna


4 Answers

If the control is not visible, it is effectively disabled. Clicking in the area where it would appear (or rolling in and out of that area) were it visible will not cause an event to fire.

EDIT: To clarify, based on other responses and comments, the button is not disabled and underlying event functionality is still available programmatically, but the button will not be physically available/visible on the form and the user will not be able to interact with it in any way (unless you, as the programmer, provide another method programmatically).

like image 82
Michael Todd Avatar answered Nov 14 '22 10:11

Michael Todd


Setting Visible to false does not change the Enabled property. However, setting the property to false does make the control effectively not even there. If you click in the empty space left by an invisible the button, the button's click event won't fire.

like image 39
Joel Coehoorn Avatar answered Nov 14 '22 09:11

Joel Coehoorn


I don't think it implies it is disabled. It just means the control is not visible on the form hence there is no way to perform the action on it. If you set the visible property to false and then invoked the Click event through code it would process. However, if you set the Enabled property to False I would imagine it wouldn't

like image 41
James Avatar answered Nov 14 '22 10:11

James


Pretty sure if .Visible = false, the '_Click' action is disabled. For instance, if you .PerformClick() in your code, and .Visible = true, _Click will execute. If false, _Click will not execute.

like image 30
guest Avatar answered Nov 14 '22 09:11

guest