ikel
ikel

Reputation: 1978

dialogresult does not work or partially work for some reason

I made a form to be a dialog and the form only has one textbox, one OK button and one Cancel button. somehow, when the following does not work unless i change rnmForm.DialogResult!=DialogResult.OK), why is that????

 frmRename rnmForm = new frmRename();

        rnmForm.ShowDialog(new Form());
        if (rnmForm.DialogResult==DialogResult.OK)
        {
            MessageBox.Show("test");

        }

Upvotes: 0

Views: 346

Answers (1)

Jay
Jay

Reputation: 6027

Did you make sure to set the dialog result to OK, before you close the dialog in the Ok click event?

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

Or setting the property on the Ok button, similar to this:

 btnOk.DialogResult = DialogResult.OK;

I also have to ask why you are calling showDialog and specifying a new instance of your form to be the owner, instead of just calling it with no parameters. Just not sure that was intentional.

rnmForm.ShowDialog();

Upvotes: 1

Related Questions