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
Re: Accessing Form Label from Seperate Class
Sorry, forgot to mention I am using VS 2008 (.NET 3.5).
Brian Enderle
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
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.
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"
Re: Accessing Form Label from Seperate Class
Quote:
What BigEd says is right, but you can do it by setting the "Modifiers" property of the label to "public"
Sssshhhhhh...