Add a groupbox from a class
As a general rule, I don't write classes that do any graphical or user interface (UI) work. The reason is because that limits the usefulness of the class because you've now hard-wired the name of some interface object to the code.
As a work-around, ask yourself if you really need the class to add a groupbox to a form. Chances are, you don't. For example, could you write a method in the class that toggles the groupbox's Visibility property from False to True? This means, of course, that the groupbox is always on the form...only its visibility changes. You could pass the Groupbox ID into the class and have the method set it there. This makes the class more flexible since you don't have to hard-code the name of the Groupbox into the class.
It's pretty hard for me to think of a good example where I need a class to do some kind of direct interface work. As a general rule, I try to keep all UI stuff outside of my classes, leaving the UI code as part of the form itself.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
|