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?
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).
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With