When working on a project to display and compare source codes, I often had to change my GUI. Inside the GUI, different flags, options etc., can be chosen to perform different process tasks. Whenever I added a new
CheckBox, I had to redesign the GUI and write a lot of code (starting inside the GUI and finally ending inside the process).
Therefore, I decided to create a class which does most of this work automatically:
EnumGroupBox class is inherited from a
GroupBox, and contains some
CheckBoxes are created using an
Enum as template. Every member of the
Enum is represented by a
EnumGroupBox class, in general, can be used for every application without changes. It fires an
EnumChanged event to the parent form. The
EnumGroupBox class itself is bound to a variable inside a different class,
ProcessOptions, representing the process flags and the options of the individual application.
EnumGroupBox properties the programmer can define are:
- Size of the single controls.
- Position of the upper left control inside the
- Row and column offsets of the other controls.
- Whether to auto-title the
EnumGroupBox with the name of the
Using the code
To use the code, there are four steps:
First, define the
Enum and a corresponding property inside the
ProcessOptions class, like:
public enum ESpecialSort
NoSpecialSort = 0,
ElseSort = 1,
CaseSort = ElseSort << 1
private ESpecialSort m_SpecialSort;
public ESpecialSort SpecialSort
m_SpecialSort = value;
enum name must be the property name preceded by an 'E'. The name of the corresponding local variable is arbitrary.
Second, inside your GUI, define a variable containing the process flags and options:
Private processType As New NSourceStructure.ProcessOptions
Third, inside your GUI designer, put an
EnumGroupBox control onto your form. (In the sample, its name is '
Load event, define for the
Fourth, define the actions for the
EnumChanged event, like:
Private Sub egbSpecialSort_EnumChanged(ByVal sender As Object, _
ByVal a As NEnumGroupBox.EnumGroupBox.CheckArgs) _
processType.SpecialSort = CType(a.Value, _
lblSpecialSort.Text = CType(CType(a.Value, Int16), String)
If processType.Check(NSourceStructure.ProcessOptions.ESpecialSort.CaseSort) Then
MsgBox("NSourceStructure.ProcessOptions.ESpecialSort.CaseSort is activated")
Points of Interest
Currently, inside the
EnumChanged event, the value of the corresponding
ProcessOption has to be set. Would be nice if somebody finds a way to do this inside the
The code is written under Visual Studio 2003, with the .NET Framework 1.1.
- It also can be compiled with Visual Studio 2005 and .NET Framework 2.0.
- After converting the project, you just have to redefine some references. Source code changes are not necessary.
I preferred the 2003 version because I think that this is still the standard IDE of most CodeProject readers.
Like explained in the beginning, the demo sample contains the
ProcessOptions class from a project, 'Source Explorer', I'm working on. So the names of the flags and options reflect a little bit the features of the final application. That project will be published here later. As writing articles for the CodeProject is not my primary profession, publishing of the final article may take a while. Sorry!
- 07-Apr-2006 - First version.
- 14-Apr-2006 - Second version:
- Added '
AttributeDescription' feature as suggested by Uwe Keim.
- Added '
AutoSize' feature as a 'Point of Interest' of the first version.
- Added the ability to change some properties at runtime.