M
Mark Broadbent
I know this has been discussed before, but rather than spend ages trawling
through old threads I thought I would start a new *quick* Q&A thread.
Q. What is the preferred method for returning data from a dialog to a parent
form.
Previously when I have been launching a dialog, I would pass a reference to
it's parent form in the ShowDialog method e.g. myDialog.ShowDialog(this)
from within the dialog I return the data by obtaining a reference from the
dialog's owner property and set the owner form value from within the
relevant dialog handler (e.g. the OK button).
However recently I have seen examples of getting the data from the dialog
from within the owner form code e.g.
FormDialog myForm = new FormDialog();
if (myForm.ShowDialog(this) == Forms.DialogResult.OK)
{
this.textBoxDialogResult.Text = myForm.textBoxReturnValue.Text;
}
Now the second method certainly seems slightly quicker (might be imagining
it), flexible, code efficient and transparent; but which is the recommended
method?
Q.2
Also another thing that needs to be done for this to work in either event is
for the member in the other instance that is being referred to from the
current one to be exposed as public (for instance as
"myForm.textBoxReturnValue"). Should this be accessed via public property
(as I expect) from a purest point of view or does it not really matter?
(Obviously using the second method, it would be the dialog which exposes the
public property -which I think is probably a more logical design)
Thanks in advance,
Br,
Mark.
through old threads I thought I would start a new *quick* Q&A thread.
Q. What is the preferred method for returning data from a dialog to a parent
form.
Previously when I have been launching a dialog, I would pass a reference to
it's parent form in the ShowDialog method e.g. myDialog.ShowDialog(this)
from within the dialog I return the data by obtaining a reference from the
dialog's owner property and set the owner form value from within the
relevant dialog handler (e.g. the OK button).
However recently I have seen examples of getting the data from the dialog
from within the owner form code e.g.
FormDialog myForm = new FormDialog();
if (myForm.ShowDialog(this) == Forms.DialogResult.OK)
{
this.textBoxDialogResult.Text = myForm.textBoxReturnValue.Text;
}
Now the second method certainly seems slightly quicker (might be imagining
it), flexible, code efficient and transparent; but which is the recommended
method?
Q.2
Also another thing that needs to be done for this to work in either event is
for the member in the other instance that is being referred to from the
current one to be exposed as public (for instance as
"myForm.textBoxReturnValue"). Should this be accessed via public property
(as I expect) from a purest point of view or does it not really matter?
(Obviously using the second method, it would be the dialog which exposes the
public property -which I think is probably a more logical design)
Thanks in advance,
Br,
Mark.