Nick,
I allow Windows Forms to close the dialog, instead of coding DialogResult &
Close in the buttonOK.Click event handler.
I set the buttonOk.DialogResult property to DialogResult.OK, I then set the
Form.AcceptButton property to buttonOk. Like wise for buttonCancel, I set
buttonCancel.DialogResult to DialogResult.Cancel and Form.CancelButton to
buttonCancel.
Windows Forms will then take care of closing the form and returning the
appropriate result. No need for the buttonOk.Click event handler per se.
Also is there any difference between Show and showDialog in the way
that I should close them?
When you use Form.ShowDialog to display a dialog box, the form does not call
Dispose when you call Form.Close, so as to allow you to get the values of
your properties, if you use Form.Dispose you should call Form.Dispose when
you are done. I would use the using statement. When you use Form.Show,
Form.Close does call Form.Dispose.
Hope this helps
Jay
"Nick" <ni*********@hotmail.com> wrote in message
news:a0**************************@posting.google.c om... A lot of people say to use properties to pass variables between a main
dialog and a subdialog like so:
Form form = new Form();
if (form.ShowDialog()==DialogResult.OK)
{
string str = form.StrinValue;
}
but how should I close the dialog since if I do the following in the
sub form when the user presses OK, then I am destroying the instance
and so the property will not be set correctly or will not exist. How
should I 'close' the form??
private void buttonOK_Click(object sender, System.EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Close();
}
Also is there any difference between Show and showDialog in the way
that I should close them?
Thanks for any help.
Nick