Ok, this is bugging me, and I just can\'t figure out what is wrong...
I have made two forms. First form just has a simple button on it, which opens the other as a di
Try setting DialogResult
on button1
this.button1.DialogResult = System.Windows.Forms.DialogResult.OK;
I had an issue with the AcceptButton not working and while the DialogResult suggestion was part of the fix, I had 2 other things that needed to change:
I hope this helps someone.
Just setting the AcceptButton/CancelButton is not enough. This just tells which button should be invoked on Enter/Esc. You have to set the DialogResult in the Button handler.
You need to set the KeyPreview property of the form to True, the default value is False. Remember that if focus is set to any other button rather than the AcceptButton the Enter key will execute this button
Definitely try the tutorial How to easily apply AcceptButton and CancelButton for custom dialog box in Winform.