Dialog object access to caller's "this"?

  • Thread starter Thread starter Ray Mitchell
  • Start date Start date
R

Ray Mitchell

Hello,

I am opening a modal dialog in the standard way using something like:

....all the standard setup stuff...
dlg.ShowDialog();

I need the dialog object to be able to access some of the methods back in
the object that created it (the code above). Is there some attribute,
method, or whatever within the dialog object that provides such access or do
I need to pass a reference to the calling object into the dialog object
after it is created but before ShowDialog is called?

Thanks,
Ray Mitchell
 
When you create an instance of your dialog object, you can pass a reference
to the owner in the constructor.
 
Hi Ray,

You will need to pass the object through the Form Dialog's
constructor so that the dialog can reference back the object that
created it.
class Parent
{
void MyMethodThatCreatesTheDialog()
{
MyDialog form = new MyDialog(this);
MyDialog.ShowDialog();
}

// ...

}

Then MyDialog's constructor can keep a reference to the object
that created it.

MyDialog(Parent parent)
{
this._myParent = parent;
}

If the creating object is a windows based itself that will be the parent,
then you might like to use the ShowDialog(IWin32Window) overloaded method
to pass a reference to the parent dialog form.

Regards,
Aravind C
 
Back
Top