Click here to Skip to main content
15,894,720 members
Articles / Programming Languages / Visual Basic

EnumGroupBox - a semi-automatic GroupBox control

Rate me:
Please Sign up or sign in to vote.
4.20/5 (10 votes)
3 May 20063 min read 64.2K   822   36  
A GroupBox automatically filled using Enums as templates.
Imports NEnumGroupBox.EnumGroupBox
Namespace NEnumGroupBoxDemo
	Public Class EnumGroupBoxDemo
		Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

		Public Sub New()
			MyBase.New()

			'This call is required by the Windows Form Designer.
			InitializeComponent()

			'Add any initialization after the InitializeComponent() call

		End Sub

		'Form overrides dispose to clean up the component list.
		Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
			If disposing Then
				If Not (components Is Nothing) Then
					components.Dispose()
				End If
			End If
			MyBase.Dispose(disposing)
		End Sub

		'Required by the Windows Form Designer
		Private components As System.ComponentModel.IContainer

		'NOTE: The following procedure is required by the Windows Form Designer
		'It can be modified using the Windows Form Designer.  
		'Do not modify it using the code editor.
		Friend WithEvents lblExplain As System.Windows.Forms.Label
		Friend WithEvents lblProject As System.Windows.Forms.Label
		Friend WithEvents Label1 As System.Windows.Forms.Label
		Friend WithEvents lblOptionGroup As System.Windows.Forms.Label
		Friend WithEvents lblSpecialSort As System.Windows.Forms.Label
		Friend WithEvents Label3 As System.Windows.Forms.Label
		Friend WithEvents lblClassSort As System.Windows.Forms.Label
		Friend WithEvents Label5 As System.Windows.Forms.Label
		Friend WithEvents lblOptions As System.Windows.Forms.Label
		Friend WithEvents Label7 As System.Windows.Forms.Label
		Friend WithEvents chkCol As System.Windows.Forms.CheckBox
		Friend WithEvents chkDescription As System.Windows.Forms.CheckBox
		Friend WithEvents Label2 As System.Windows.Forms.Label
		Friend WithEvents chkThree As System.Windows.Forms.CheckBox
		Friend WithEvents chkAutoSize As System.Windows.Forms.CheckBox
		Friend WithEvents egbPredefined As NEnumGroupBox.EnumGroupBox
		Friend WithEvents egbSpecialSort As NEnumGroupBox.EnumGroupBox
		Friend WithEvents egbUnitSort As NEnumGroupBox.EnumGroupBox
		Friend WithEvents egbTasks As NEnumGroupBox.EnumGroupBox
		<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
			Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(EnumGroupBoxDemo))
			Me.lblExplain = New System.Windows.Forms.Label
			Me.lblProject = New System.Windows.Forms.Label
			Me.Label1 = New System.Windows.Forms.Label
			Me.lblOptionGroup = New System.Windows.Forms.Label
			Me.lblSpecialSort = New System.Windows.Forms.Label
			Me.Label3 = New System.Windows.Forms.Label
			Me.lblClassSort = New System.Windows.Forms.Label
			Me.Label5 = New System.Windows.Forms.Label
			Me.lblOptions = New System.Windows.Forms.Label
			Me.Label7 = New System.Windows.Forms.Label
			Me.chkCol = New System.Windows.Forms.CheckBox
			Me.chkDescription = New System.Windows.Forms.CheckBox
			Me.Label2 = New System.Windows.Forms.Label
			Me.chkThree = New System.Windows.Forms.CheckBox
			Me.chkAutoSize = New System.Windows.Forms.CheckBox
			Me.egbPredefined = New NEnumGroupBox.EnumGroupBox
			Me.egbSpecialSort = New NEnumGroupBox.EnumGroupBox
			Me.egbUnitSort = New NEnumGroupBox.EnumGroupBox
			Me.egbTasks = New NEnumGroupBox.EnumGroupBox
			Me.SuspendLayout()
			'
			'lblExplain
			'
			Me.lblExplain.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblExplain.ForeColor = System.Drawing.SystemColors.ControlText
			Me.lblExplain.Location = New System.Drawing.Point(256, 8)
			Me.lblExplain.Name = "lblExplain"
			Me.lblExplain.Size = New System.Drawing.Size(352, 48)
			Me.lblExplain.TabIndex = 4
			Me.lblExplain.Text = "Clicking a RadioButton in the 'Predefined' EnumGroupBox generates some predefined" & _
			" constellations in the other EnumGroupBoxes"
			Me.lblExplain.TextAlign = System.Drawing.ContentAlignment.TopCenter
			'
			'lblProject
			'
			Me.lblProject.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblProject.ForeColor = System.Drawing.Color.Maroon
			Me.lblProject.Location = New System.Drawing.Point(256, 56)
			Me.lblProject.Name = "lblProject"
			Me.lblProject.Size = New System.Drawing.Size(352, 32)
			Me.lblProject.TabIndex = 5
			Me.lblProject.Text = "This demo is part of the SourceExplorer project"
			Me.lblProject.TextAlign = System.Drawing.ContentAlignment.MiddleCenter
			'
			'Label1
			'
			Me.Label1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.Label1.Location = New System.Drawing.Point(16, 96)
			Me.Label1.Name = "Label1"
			Me.Label1.Size = New System.Drawing.Size(48, 24)
			Me.Label1.TabIndex = 6
			Me.Label1.Text = "Value:"
			'
			'lblOptionGroup
			'
			Me.lblOptionGroup.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblOptionGroup.Location = New System.Drawing.Point(64, 96)
			Me.lblOptionGroup.Name = "lblOptionGroup"
			Me.lblOptionGroup.Size = New System.Drawing.Size(48, 24)
			Me.lblOptionGroup.TabIndex = 7
			Me.lblOptionGroup.Text = "0"
			'
			'lblSpecialSort
			'
			Me.lblSpecialSort.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblSpecialSort.Location = New System.Drawing.Point(64, 168)
			Me.lblSpecialSort.Name = "lblSpecialSort"
			Me.lblSpecialSort.Size = New System.Drawing.Size(48, 24)
			Me.lblSpecialSort.TabIndex = 9
			Me.lblSpecialSort.Text = "0"
			'
			'Label3
			'
			Me.Label3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.Label3.Location = New System.Drawing.Point(16, 168)
			Me.Label3.Name = "Label3"
			Me.Label3.Size = New System.Drawing.Size(48, 24)
			Me.Label3.TabIndex = 8
			Me.Label3.Text = "Value:"
			'
			'lblClassSort
			'
			Me.lblClassSort.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblClassSort.Location = New System.Drawing.Point(64, 280)
			Me.lblClassSort.Name = "lblClassSort"
			Me.lblClassSort.Size = New System.Drawing.Size(48, 24)
			Me.lblClassSort.TabIndex = 11
			Me.lblClassSort.Text = "0"
			'
			'Label5
			'
			Me.Label5.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.Label5.Location = New System.Drawing.Point(16, 280)
			Me.Label5.Name = "Label5"
			Me.Label5.Size = New System.Drawing.Size(48, 24)
			Me.Label5.TabIndex = 10
			Me.Label5.Text = "Value:"
			'
			'lblOptions
			'
			Me.lblOptions.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.lblOptions.Location = New System.Drawing.Point(424, 280)
			Me.lblOptions.Name = "lblOptions"
			Me.lblOptions.Size = New System.Drawing.Size(48, 24)
			Me.lblOptions.TabIndex = 13
			Me.lblOptions.Text = "0"
			'
			'Label7
			'
			Me.Label7.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.Label7.Location = New System.Drawing.Point(376, 280)
			Me.Label7.Name = "Label7"
			Me.Label7.Size = New System.Drawing.Size(48, 24)
			Me.Label7.TabIndex = 12
			Me.Label7.Text = "Value:"
			'
			'chkCol
			'
			Me.chkCol.Location = New System.Drawing.Point(264, 160)
			Me.chkCol.Name = "chkCol"
			Me.chkCol.Size = New System.Drawing.Size(104, 16)
			Me.chkCol.TabIndex = 16
			Me.chkCol.Text = "col_by_col"
			'
			'chkDescription
			'
			Me.chkDescription.Checked = True
			Me.chkDescription.CheckState = System.Windows.Forms.CheckState.Checked
			Me.chkDescription.Location = New System.Drawing.Point(264, 192)
			Me.chkDescription.Name = "chkDescription"
			Me.chkDescription.Size = New System.Drawing.Size(104, 16)
			Me.chkDescription.TabIndex = 18
			Me.chkDescription.Text = "Descriptions"
			'
			'Label2
			'
			Me.Label2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
			Me.Label2.Location = New System.Drawing.Point(264, 104)
			Me.Label2.Name = "Label2"
			Me.Label2.Size = New System.Drawing.Size(56, 24)
			Me.Label2.TabIndex = 19
			Me.Label2.Text = "Try:"
			'
			'chkThree
			'
			Me.chkThree.Location = New System.Drawing.Point(264, 216)
			Me.chkThree.Name = "chkThree"
			Me.chkThree.Size = New System.Drawing.Size(104, 16)
			Me.chkThree.TabIndex = 20
			Me.chkThree.Text = "Three Columns"
			'
			'chkAutoSize
			'
			Me.chkAutoSize.Checked = True
			Me.chkAutoSize.CheckState = System.Windows.Forms.CheckState.Checked
			Me.chkAutoSize.Location = New System.Drawing.Point(264, 136)
			Me.chkAutoSize.Name = "chkAutoSize"
			Me.chkAutoSize.Size = New System.Drawing.Size(104, 16)
			Me.chkAutoSize.TabIndex = 21
			Me.chkAutoSize.Text = "AutoSize"
			'
			'egbPredefined
			'
			Me.egbPredefined.EnumAutoSize = True
			Me.egbPredefined.EnumBuildDirection = NEnumGroupBox.EnumGroupBox.BuildDirection.row_by_row
			Me.egbPredefined.EnumCaptDescription = NEnumGroupBox.EnumGroupBox.CaptDescription.descNo
			Me.egbPredefined.EnumCols = 2
			Me.egbPredefined.EnumRows = -1
			Me.egbPredefined.EnumSingleSize = New System.Drawing.Size(112, 16)
			Me.egbPredefined.EnumStep = New System.Drawing.Size(112, 24)
			Me.egbPredefined.EnumUpperLeft = New System.Drawing.Point(8, 16)
			Me.egbPredefined.Location = New System.Drawing.Point(8, 8)
			Me.egbPredefined.Name = "egbPredefined"
			Me.egbPredefined.Size = New System.Drawing.Size(232, 72)
			Me.egbPredefined.TabIndex = 22
			Me.egbPredefined.TabStop = False
			'
			'egbSpecialSort
			'
			Me.egbSpecialSort.EnumAutoSize = True
			Me.egbSpecialSort.EnumBuildDirection = NEnumGroupBox.EnumGroupBox.BuildDirection.row_by_row
			Me.egbSpecialSort.EnumCaptDescription = NEnumGroupBox.EnumGroupBox.CaptDescription.descNo
			Me.egbSpecialSort.EnumCols = 2
			Me.egbSpecialSort.EnumRows = -1
			Me.egbSpecialSort.EnumSingleSize = New System.Drawing.Size(112, 16)
			Me.egbSpecialSort.EnumStep = New System.Drawing.Size(112, 24)
			Me.egbSpecialSort.EnumUpperLeft = New System.Drawing.Point(8, 16)
			Me.egbSpecialSort.Location = New System.Drawing.Point(8, 120)
			Me.egbSpecialSort.Name = "egbSpecialSort"
			Me.egbSpecialSort.Size = New System.Drawing.Size(240, 40)
			Me.egbSpecialSort.TabIndex = 23
			Me.egbSpecialSort.TabStop = False
			'
			'egbUnitSort
			'
			Me.egbUnitSort.EnumAutoSize = True
			Me.egbUnitSort.EnumBuildDirection = NEnumGroupBox.EnumGroupBox.BuildDirection.row_by_row
			Me.egbUnitSort.EnumCaptDescription = NEnumGroupBox.EnumGroupBox.CaptDescription.descNo
			Me.egbUnitSort.EnumCols = 2
			Me.egbUnitSort.EnumRows = -1
			Me.egbUnitSort.EnumSingleSize = New System.Drawing.Size(112, 16)
			Me.egbUnitSort.EnumStep = New System.Drawing.Size(112, 24)
			Me.egbUnitSort.EnumUpperLeft = New System.Drawing.Point(8, 16)
			Me.egbUnitSort.Location = New System.Drawing.Point(8, 192)
			Me.egbUnitSort.Name = "egbUnitSort"
			Me.egbUnitSort.Size = New System.Drawing.Size(240, 80)
			Me.egbUnitSort.TabIndex = 24
			Me.egbUnitSort.TabStop = False
			'
			'egbTasks
			'
			Me.egbTasks.EnumAutoSize = True
			Me.egbTasks.EnumBuildDirection = NEnumGroupBox.EnumGroupBox.BuildDirection.row_by_row
			Me.egbTasks.EnumCaptDescription = NEnumGroupBox.EnumGroupBox.CaptDescription.descYes
			Me.egbTasks.EnumCols = 2
			Me.egbTasks.EnumRows = -1
			Me.egbTasks.EnumSingleSize = New System.Drawing.Size(112, 16)
			Me.egbTasks.EnumStep = New System.Drawing.Size(112, 24)
			Me.egbTasks.EnumUpperLeft = New System.Drawing.Point(8, 16)
			Me.egbTasks.Location = New System.Drawing.Point(368, 96)
			Me.egbTasks.Name = "egbTasks"
			Me.egbTasks.Size = New System.Drawing.Size(248, 136)
			Me.egbTasks.TabIndex = 25
			Me.egbTasks.TabStop = False
			'
			'EnumGroupBoxDemo
			'
			Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
			Me.ClientSize = New System.Drawing.Size(634, 303)
			Me.Controls.Add(Me.egbTasks)
			Me.Controls.Add(Me.egbUnitSort)
			Me.Controls.Add(Me.egbSpecialSort)
			Me.Controls.Add(Me.egbPredefined)
			Me.Controls.Add(Me.chkAutoSize)
			Me.Controls.Add(Me.chkDescription)
			Me.Controls.Add(Me.chkThree)
			Me.Controls.Add(Me.Label2)
			Me.Controls.Add(Me.chkCol)
			Me.Controls.Add(Me.lblOptions)
			Me.Controls.Add(Me.Label7)
			Me.Controls.Add(Me.lblClassSort)
			Me.Controls.Add(Me.Label5)
			Me.Controls.Add(Me.lblSpecialSort)
			Me.Controls.Add(Me.Label3)
			Me.Controls.Add(Me.lblOptionGroup)
			Me.Controls.Add(Me.Label1)
			Me.Controls.Add(Me.lblProject)
			Me.Controls.Add(Me.lblExplain)
			Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
			Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
			Me.Name = "EnumGroupBoxDemo"
			Me.Text = "EnumGroupBox Demo"
			Me.ResumeLayout(False)

		End Sub

#End Region

		Private processType As New NSourceStructure.ProcessOptions
#Region "Standard Events"
		Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

			' the Windows Form Designer creates the EnumGroupBoxes and sets 
			' their location, size etc.
			'
			' we have to tell them about the underlying enums
			'
			' you must define the enum and the type
			egbPredefined.EnumSource(processType.Predefined, ControlType.radioButton)

			' same again for the other EnumGroupBoxes
			egbUnitSort.EnumSource(processType.UnitSort, ControlType.radioButton)
			egbSpecialSort.EnumSource(processType.SpecialSort, ControlType.checkBox)
			egbTasks.EnumSource(processType.Tasks, ControlType.checkBox)

			' for our demo program, predefine "no options"
			egbPredefined.Value = NSourceStructure.ProcessOptions.EPredefined.Nothing
		End Sub

		Private Sub chkAutoSize_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkAutoSize.CheckedChanged
			egbTasks.EnumAutoSize = CType(sender, CheckBox).Checked
		End Sub

		Private Sub chkCol_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkCol.CheckedChanged
			If CType(sender, CheckBox).Checked = False Then
				egbTasks.EnumBuildDirection = BuildDirection.row_by_row
			Else
				egbTasks.EnumBuildDirection = BuildDirection.col_by_col
			End If
		End Sub
		Private Sub chkDescription_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkDescription.CheckedChanged
			If CType(sender, CheckBox).Checked Then
				egbTasks.EnumCaptDescription = CaptDescription.descYes
			Else
				egbTasks.EnumCaptDescription = CaptDescription.descNo
			End If
		End Sub
		Private Sub chkThree_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkThree.CheckedChanged
			If CType(sender, CheckBox).Checked Then
				egbTasks.EnumCols = 3
			Else
				egbTasks.EnumCols = 2
			End If
			Me.Width = egbTasks.Left + egbTasks.Width + 20
		End Sub
#End Region

#Region "EnumGroupBox events"
		' handle the events coming from the different EnumGroupBoxes
		Private Sub egbSpecialSort_EnumChanged(ByVal sender As Object, ByVal a As NEnumGroupBox.EnumGroupBox.CheckArgs) Handles egbSpecialSort.EnumChanged
			' because the EnumGroupBox does not know about the 'parent' Enum,
			' we have to set the 'parent' value here by passing the values to the process defining class
			processType.SpecialSort = CType(a.Value, NSourceStructure.ProcessOptions.ESpecialSort)
			' execute your special code using the new value
			lblSpecialSort.Text = CType(CType(a.Value, Int16), String)
			' to check for a single flag use the code:
			' <processType>.Check(<flag>)
			' The flag check may be anywhere in your program.
			' it is here for example only
			If processType.Check(NSourceStructure.ProcessOptions.ESpecialSort.CaseSort) Then
				MsgBox("NSourceStructure.ProcessOptions.ESpecialSort.CaseSort is activated")
			End If
		End Sub
		Private Sub egbUnitSort_EnumChanged(ByVal sender As Object, ByVal a As NEnumGroupBox.EnumGroupBox.CheckArgs) Handles egbUnitSort.EnumChanged
			processType.UnitSort = CType(a.Value, NSourceStructure.ProcessOptions.EUnitSort)
			lblClassSort.Text = CType(CType(a.Value, Int16), String)
		End Sub

		Private Sub egbOptions_EnumChanged(ByVal sender As Object, ByVal a As NEnumGroupBox.EnumGroupBox.CheckArgs) Handles egbTasks.EnumChanged
			processType.Tasks = CType(a.Value, NSourceStructure.ProcessOptions.ETasks)
			lblOptions.Text = CType(CType(a.Value, Int16), String)
		End Sub


		Private Sub egbOptionGroup_EnumChanged(ByVal sender As Object, ByVal a As NEnumGroupBox.EnumGroupBox.CheckArgs) Handles egbPredefined.EnumChanged
			processType.Predefined = CType(a.Value, NSourceStructure.ProcessOptions.EPredefined)
			' changing processType.OptionGroup causes changes in
			' processType.Tasks, processType.UnitSort() and processType.SpecialSort 
			' we have to pass the new information every of the corresponding EnumGroupBoxes
			egbTasks.Value = CInt(processType.Tasks)
			egbUnitSort.Value = CInt(processType.UnitSort)
			egbSpecialSort.Value = CInt(processType.SpecialSort)
			lblOptionGroup.Text = CType(CType(a.Value, Int16), String)
		End Sub
#End Region

	End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
Peter Schlang, working with computers since 1974
Developing mainly for newspapers since 1981, first as employee of ATEX
Freelancer since 1987
Preferred language is VB: Starting with VB 1.0 and VBDOS, up to VB.NET

Comments and Discussions