Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 sound normal?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
431 views
Welcome To Ask or Share your Answers For Others

1 Answer

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;
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...