Winforms button: Does Visible = false imply Enable

2019-02-22 02:44发布

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?

4条回答
我只想做你的唯一
2楼-- · 2019-02-22 02:55

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

查看更多
Bombasti
3楼-- · 2019-02-22 03:00

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.

查看更多
Summer. ? 凉城
4楼-- · 2019-02-22 03:03

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

查看更多
一夜七次
5楼-- · 2019-02-22 03:07

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.

查看更多
登录 后发表回答