accessing controls on another form

  • Thread starter Thread starter cm@gowcity
  • Start date Start date
C

cm@gowcity

HI, here's my problem;

My application loads up 3 forms at startup.
Deppending on what button is press on form1 i want to show or hide
controls on form2.
I cant seem to get access to the controls on from2 to hide them unless
i create another instance from within form1 which i dont want to do. i
just want to use the one creted when the program starts up.

Any ideas?
 
Hi,

Basically you need to keep a reference to the form2 in form1 , in such a
way that when you need to make changes on form2 you have it accesible from
form1.
something like this:

class Form1 {
Form2 form2;

public Form1()
{
//create form2;
form2 = new Form2();
//as you show both forms from the very beginning , let's show it
form2.Show();
}
//Now I can do this:
protected button_OnClick( object s, EventArgs e )
{
form2.MakeChanges();
}

}


Hope this help,
 
HI, here's my problem;

My application loads up 3 forms at startup.
Deppending on what button is press on form1 i want to show or hide
controls on form2.
I cant seem to get access to the controls on from2 to hide them unless
i create another instance from within form1 which i dont want to do. i
just want to use the one creted when the program starts up.

Any ideas?

You could also use delegates.
check out
http://www.codeproject.com/csharp/#Delegates+and+Events

for examples using delegates.
 
Back
Top