WinForms Close() sets DialogResult to Cancel

后端 未结 2 1546
野性不改
野性不改 2020-12-16 10:51

If I call Close() in my WinForm, it seems that even though DialogResult is None at the time, right after I call Close() I see that it is set to Cancel.

Does this sou

2条回答
  •  情话喂你
    2020-12-16 11:11

    Or even easier, you can set DialogResult just after Close. For example, assuming ValidateSettings will show the user any problems with the form or return true otherwise:

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (ValidateSettings())
            {
                SaveSettings();
                Close();
                DialogResult = DialogResult.OK;
            }
        }
    

提交回复
热议问题