PC Review


Reply
Thread Tools Rate Thread

Advice on coding my classes

 
 
Willie Neal
Guest
Posts: n/a
 
      22nd May 2004
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








 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
newb advice on classes mp Microsoft C# .NET 7 3rd Apr 2010 06:06 PM
Advice needed on classes integration FP Microsoft C# .NET 0 28th Nov 2007 01:32 PM
Need Coding Advice =?Utf-8?B?QW5uZQ==?= Microsoft Access VBA Modules 3 24th Jan 2006 04:19 PM
Can you instantiate classes without hard-coding class names?? ALittle Microsoft Excel Programming 2 24th Nov 2005 01:59 AM
Advice on Coding standards =?Utf-8?B?dnZlbms=?= Microsoft VB .NET 4 21st Nov 2004 05:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:32 AM.