Winforms button: Visible = false implies Enabled = false?

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

+6
button winforms
source share
4 answers

If the control is not displayed, it is effectively disabled. A click in the area where it appeared (or rolled in and out of this area), if it was visible, would not trigger an event.

EDIT: To clarify, based on other answers and comments, the button is not disabled, and the basic functions of the events are still available programmatically, but the button will not be physically accessible / visible in the form, and the user will not be able to interact with it in any way (if you as a programmer, do not suggest another method programmatically).

+5
source share

Setting Visible to false does not change the Enabled property. However, setting the property to false makes the control effective even there. If you click on an empty space left by an invisible button, the button press event will not fire.

+1
source share

I do not think this means that it is disabled. It just means that the control is not displayed on the form, so there is no way to perform an action on it. If you set the visible property to false, and then raise the Click event through the code that it will handle. However, if you set the Enabled property to False, I would assume that it would not

+1
source share

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

+1
source share

All Articles