Aug 23, 2011
There is newer code in a follow up post. I suggest using the code in the later post rather than the code in this one. You can still read this post though. When designing a user interface, one should be conscious of how many individual controls are required to implement the functionality. In some cases an initial design may begin with many buttons or textboxes (for example) but then further review of
View 9 Replies
the actual required functionality allows for a reduction in the number of unique controls.
But other times, there isn't a better way (which will still make sense to the user of the application) then to have a series of many repeated controls. So in the cases where one can be certain that the best UI implementation for an application will require the use of multiple copies of a given control, then it often becomes necessary to maintain some method of managing all of those controls at various points
throughout the application. Doing so typically requires that one build up some collection of controls which can then be accessed by index in order to work with any given control; but this can lead to a lot of clutter in the code file which handles these control's events. For instance there will be some kind of collection declaration, some recursive routine to find all of the controls of interest, and then any number of event handler methods with long lists of Handles clauses, or additional code loops to wire up the event handling for each control.
Purpose Since most of this functionality could be considered a requirement regardless of the type of control being managed, or its required functionality, it may make sense to wrap all of the control management functionality into a single class. And since our first requirement is a collection of controls, then a base collection class could be the perfect starting point for our control manager. There are a number of existing thread around this topic, with some recent (at the time of this writing) ones being:[URL]..In this, and related, threads I have posted examples of a simple TextBoxManager and ButtonManager control. But again, with so much similar functionality required regardless of the control being managed, it would be technically possible to create a generic ControlManager(Of T As Control) class which can manage any type of control.
So in summary, one can facilitate managing a large number of user interface controls by building a "control manager" class which both encapsulates the list of control instances, and deals with adding and removing defined event handlers for every control it manages. The generic control manager class itself can be inherited and extended into a more specific class on a per-application basis in order to provide more application-specific functionality. Reed Kimble - "When you do things right, people won't be sure you've done anything at all"