|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Raise event or return structure??I have a class that performs some functions and then needs to update some labels on the main form (from which it is called) with several pieces of information, some text, some datetime etc, according to the results of the calculations. I can see at least a couple of ways of doing this: 1. Define a structure that contains all the items of information that I need to pass back and assign a variable with this structure as the return value to the calling routine in the main form. (Assuming I can do this.) 2. Raise a custom event in the client class that passes the required data items as separate arguments. Monitor this event in the main form and update the form labels whenever the event is raised. Any views on which of these options might be preferred (or any other alternatives? JGD Either way, you are going to end up populating some sort of class or
structure - either as the return value, or as a custom EventArgs class. The question really is if this method is the only time these values can change, and conceptually how these values can change. Sometimes an event feels right, because something is changing, and you want to raise an event to notify any listeners. If there are several ways that something can change, this makes even more sense. However, if the function is ComputeLabelValues - then that function should return the label values it computed as the return value. And nothing else would ever change these values, so that is fine. Show quoteHide quote "John Dann" <n***@prodata.co.uk> wrote in message news:rrdt829c7nuupn9eru9rtf4oe7ti1pn6jr@4ax.com... > VB.Net 2005: > > I have a class that performs some functions and then needs to update > some labels on the main form (from which it is called) with several > pieces of information, some text, some datetime etc, according to the > results of the calculations. > > I can see at least a couple of ways of doing this: > > 1. Define a structure that contains all the items of information that > I need to pass back and assign a variable with this structure as the > return value to the calling routine in the main form. (Assuming I can > do this.) > > 2. Raise a custom event in the client class that passes the required > data items as separate arguments. Monitor this event in the main form > and update the form labels whenever the event is raised. > > Any views on which of these options might be preferred (or any other > alternatives? > > JGD
Inserting Variables in a Document
RANT: option strict etc c# to vb.net getting screen coordinates for positioning a floating control next to a tableLayOutPanel embeded con Emulating keyboard strokes in vb.net Refer to sheet2 - even when named To catch when a process is terminated PrinterSettings.PrintRange, print only selected pages. Help with C# to VB.Net ... Please cast from string to button |
|||||||||||||||||||||||