Is the Windows Forms AcceptButton behavior in effect when the referenced button is disabled?

541 Views Asked by At

With the following:

this.AcceptButton = this.OKButton;
this.OKButton.Enabled = false;

... will the OK button click handler still be invoked when the user presses Enter?

3

There are 3 best solutions below

0
Daniel LeCheminant On BEST ANSWER

No, it won't be invoked.

0
Adam Davis On

No, when the button is disabled, it will not activate and trigger that event.

-Adam

0
Powerlord On

AcceptButton/CancelButton just call the button's PerformClick() method... which doesn't run if the control is disabled.