I'm new to vb.net and would like the advice of my peers. Here is my
scenario: I have a user control which consists of three buttons, three
listboxes and three labels. When the user selects a button an associated
listbox is made visible. The user can then select her choices which will be
used for a reporting filter down the line. I've created a user control to
house these controls and put the user control on a form, I will have perhaps
4 different user controls later. I've create a class called clsCustomCtl
which has two classes in it, one for button which inherits button and one
for listbox which inherits listbox. I then instantiate these classes in my
user control making my controls of the class type, clsButton or clsList.
Here is my code below, am I coding this in a correct manner? I'm a stickler
for coding style, but being new to .net I would love some advice. Through a
property assignment I'm assigning each button a list box and each list box
I'm assigning a label control showing whether the listbox items were
selected are not. I assume since the button has control over the listbox,
doing it in this manner allows the same functionality for all buttons
derived from clsButton. All the button does is toggles the visible property
showing it's assigned list box control and as Items are selected in the
listbox the label displays text of some kind. Thanks you for taking the
time, sorry so verbose.
Code from User Control:
Private Sub IntitializeCtls()
Me.ListBox1.uLabel = Me.Label1
Me.ListBox2.uLabel = Me.Label2
Me.ListBox3.uLabel = Me.Label3
Me.Button1.uListBox = Me.ListBox1
Me.Button3.uListBox = Me.ListBox3
Me.Button2.uListBox = Me.ListBox2
End Sub
CLASS CODE:
Imports System.Windows.Forms
Public Class clsButton
Inherits Windows.Forms.Button
Private _lst As ListBox
Public Property uListBox() As ListBox
Get
Return _lst
End Get
Set(ByVal Value As ListBox)
_lst = Value
End Set
End Property
Public Sub New()
MyBase.New()
RemoveHandler Me.Click, AddressOf Button_click
AddHandler Me.Click, AddressOf Button_click
End Sub
Private Sub Button_click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Me.uListBox.Visible = True
Me.uListBox.BringToFront()
If Me.uListBox.Visible Then
Me.uLabel.Visible = True
Else
Me.uLabel.Visible = False
End If
End Sub
End Class
Public Class clsList
Inherits Windows.Forms.ListBox
Private _lbl As Label
Public Property uLabel() As Label
Get
Return _lbl
End Get
Set(ByVal Value As Label)
_lbl = Value
End Set
End Property
Public Sub New()
MyBase.New()
MyBase.SelectionMode = SelectionMode.MultiSimple
RemoveHandler Me.Click, AddressOf clsList_Click
AddHandler Me.Click, AddressOf clsList_Click
End Sub
Private Sub clsList_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Click
Me.uLabel.Text = "Filtered"
End Sub
End Class
|