Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get/set Form1.label1 from Form2 without being MDI 1

Status
Not open for further replies.

cjtaylor

Programmer
Aug 12, 2001
69
US
Hello,

I am comming from the Borland world of programming where you could access one form from another just by using a simple include statement.

How do you change the value of a label on Form1 from Form2 without being an MDI application?

Thanks
 
It should be a simple case of changing the protection level of the label in Form1. This can then be accessed from Form2.
In theory ... :)
Steve
 
Thanks Steve for your reply. I had to take it couple of steps further. This is what I had to do, if anyone in the future wants to know.

I created a Global class named Globals.cs. Within the class I specified a public static field like the following:

public static MainForm MainFormRef;

I assigned a reference to the MainForm in the Load event, like the following.

private void MainForm_Load(object sender, System.EventArgs e)
{
Globals.MainFormRef = this;
}

Now I access my MainForm through any form in my app.

Make sure any functions you have in the referenced form are declared as public. In my case I changed the private attribute of the label I was trying to access to public.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top