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.
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.

how to refer to the form that caused: form2.show
Chris128
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.
schmack
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...
public partial class Form1 : Form
{
/*...*/
public void ShowForm2()
{
Form2 FormToShow = new Form2();
FormToShow.ShownByForm = this;
FormToShow.Show();
}
}
public partial class Form2 : Form
{
/*...*/
private Form _shownByForm = null;
public Form ShownByForm
{
get { return _shownByForm; }
set { _shownByForm = value; }
}
}
HTH
Computer Guy69146
what if we use showdialog. is there a built in way
Thanks for the solution for show method.
papermater
msadekd
How do I get a reference to form1.
Neither using parent nor owner in form2 has worked for referencing the form that instantiated the current form with: form2.show
THnaks.