-
July 16th, 2010, 12:19 PM
#1
Accessing Form Label from Seperate Class
I am trying to update a labels text field from a class that is separate from the form class. I have created a UpdateStats class file to handle all the updating of stats, querying the database, etc. This class also runs as a background worker so it is on a separate thread from the form.
As the stat values are updated by UpdateStats I would like to update the label's text field in statsForm. I have implemented events/listeners to do this but I can not find a way to reference the label that I wish to update.
What is the best way to handle this?
Thanks,
Brian Enderle
-
July 16th, 2010, 12:21 PM
#2
Re: Accessing Form Label from Seperate Class
Sorry, forgot to mention I am using VS 2008 (.NET 3.5).
Brian Enderle
-
July 16th, 2010, 12:24 PM
#3
Re: Accessing Form Label from Seperate Class
Also forgot to mention that there will be a number of these labels that I will be updating so I would prefer not to have to setup a separate listener or method for each label. I would prefer to have one listener that I could somehow reference the label via a parameter.
Brian Enderle
-
July 16th, 2010, 01:48 PM
#4
Re: Accessing Form Label from Seperate Class
You are approaching this in the wrong way. The UI code should be as centralized as possible; data classes should not be responsible for updating the UI, it creates a tight coupling between logically disparate areas of code, which in turn creates a maintenance headache.
Your data classes can simply return values and/or expose events that the UI (i.e., the Form class) can handle. The Form would then update the labels as needed. This way you do not have to maintain several areas of code when you wish to change the UI. Your data classes can remain intact and you only need edit your UI code.
-
July 16th, 2010, 06:59 PM
#5
Re: Accessing Form Label from Seperate Class
What BigEd says is right, but you can do it by setting the "Modifiers" property of the label to "public"
--------------------------------------------------------------------------------------------------------------------------
Disclaimer - Most likely any code I have posted as an answer was most likely written free hand and may have some minor compile errors, and is merely intended to give you the idea.
-
July 16th, 2010, 11:50 PM
#6
Re: Accessing Form Label from Seperate Class
Originally Posted by matthewsanford@gmail.com
What BigEd says is right, but you can do it by setting the "Modifiers" property of the label to "public"
Sssshhhhhh...
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|