C#: How do you send OK or Cancel return messages of dialogs when not using buttons?

后端 未结 3 1991
天命终不由人
天命终不由人 2020-12-15 02:46

C#: How do you send OK or Cancel return messages of dialogs when not using buttons?

How would you return the OK message in the condition of a textbox that will proce

相关标签:
3条回答
  • 2020-12-15 02:53

    I assume you're using Windows Forms...

    A couple of ways.

    For OK - set AcceptButton on the form to the OK button. For Cancel - set Cancelbutton on the form to the cancel button.

    OR, you can manually set the forms DialogResult to DialogResult.OK or DialogResult.Cancel and then close the form programatically.

    0 讨论(0)
  • 2020-12-15 02:55

    Directly, in the properties of the button itself, there is the DialogResult property that can be set to OK/Cancel/Yes/No/etc... As the others have said, this can also be set programmatically.

    In the properties of the form the button is on, set the AcceptButton property to your button. This will also do things like trigger the button when you hit the enter key, and highlight the button.

    0 讨论(0)
  • 2020-12-15 03:10

    Set the form's DialogResult:

    this.DialogResult = DialogResult.OK;
    this.Close();
    

    This would cause any opener that opened this form with ShowDialog() to get the given DialogResult as the result.

    0 讨论(0)
提交回复
热议问题