Hi if I have a form1 where i call : form2.show In the code of form2, how do I refer to form1 I tried me.parent and me.owner in form2 but they didn t work Thanks for your help.
There is no built-in knowledge of what form caused another form to show... after all, pretty much any code could have shown the Form2, not just something within Form1.
If you really need this association, then the easiest thing would be to add a public property to Form2 (call it "ShownByForm" for example). Then set this property just before showing the form...
publicpartialclassForm1 : Form
{
/*...*/
publicvoid ShowForm2()
{
Form2 FormToShow = newForm2();
FormToShow.ShownByForm = this;
FormToShow.Show();
}
}
publicpartialclassForm2 : Form
{
/*...*/
privateForm _shownByForm = null;
publicForm ShownByForm
{
get { return _shownByForm; }
set { _shownByForm = value; }
}
}
HTH
R.Tutus
Posted: Visual C# General, how to refer to the form that caused: form2.show
Same situation for ShowDialog(). ShowDialog is not much more than a Show() that temporarily takes over the main thread of the application until the modal dialog is closed.