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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting GUI object from another class?

Status
Not open for further replies.

malben

Programmer
Jun 20, 2006
1
0
0
GB
Hi,

I've created an GUI form in C# on .NET (called form1). I also have another class (class1) with no GUI stuff in it, what I want to do is for a function in Class1 to set a label on form1.
But, Im not sure how you do it? I've tried to inherit form1 into Class1, but with no luck.

Would anyone know how I should do it?

Thanks in advance for your help!
 
Pass a reference to the label in form1 to class1 when you create it, save it there and the update it from there.
Make sure the label is declared public in form1
 
wha?

Your label should reflect a piece of data in a class. When the class is updated it should fire some kind of event to let all views know that the data changed. That's when the label would automatically update itself from the event.

It is bad practice to make controls public. It's like defining global variables. How can you control who changes it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top