Referencing the owner of a form

  • Thread starter Thread starter Maart_newbie
  • Start date Start date
M

Maart_newbie

Hi all,

I have a an instance of a form, lets say Form2, that is constructed
from within a event handler of an instance of Form1, subsequently I
call ShowDialog with the instance of Form1 as its owner:

form2 = gcnew Form2();
form2->ShowDialog(this);

Form1 is constructed within main through generated code by VS2005:

int main(array<System::String ^> ^args)
{
// Enabling Windows XP visual effects before any controls are created
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);

// Create the main window and run it
Application::Run(gcnew Form1());
return 0;
}

Now, when I try to reference the public members (e.g. dataAdapter) of
the instance of Form1 from the instance of Form2 (form2), I receive the
following error:

'dataAdapter' : is not a member of 'System::Windows::Forms::Form'

Can anybody help me out with this? How can I reference the instance of
Form1 that is constructed in main from within form2?

Thank in advance

Maart
 
'Fixed' it

I had to cast back the owner:

Form1^ f1 = (Form1^) this->Owner;

Subsequently its members were available.

Maart
 
Back
Top