How can I reference a Windows Form

  • Thread starter Thread starter Oney
  • Start date Start date
O

Oney

How can I reference a Windows Form

In details;
I created two Form (frm1,frm2)
I want to reach frm1 controls from frm2 in runtime. So I have to reference frm1
by the way there is no mdi form

is it possible? any idea

thanks
 
Hi Oney,

Define a special constructor for frm2 that takes a Form reference.

public class Form2 : Form
{
Form1 frm1;

public Form2() {}
public Form2(Form1 frm)
{
frm1 = frm;
}

public void SomeMethod()
{
// do something with frm1, which is a reference to Form1
}
}

Then when you instantiate Form2, call it something like this:

frm2 = new Form2(this);

As a matter of proper coding style, don't expose your controls publicly.
Instead, define public properties and methods that encapsulate the internal
state of your form.

Joe
 
Back
Top