Ron wrote:
NOW lets say I want to use that class on this frown button click event?
How would the code look? I was thinking :
Public Class Form1
Private Sub btnFrown_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnFrown.Click
lblface.text = faces.f
End Sub
You've created a Class called Faces. So far, so good.
To use the methods it provides, you must create an Instance of that
class (an Object of Type Faces), something like
Dim f as New Faces
lblFace.Text = f.frown ' public property, not private variable
Alternatively, you could make your properties (and private variables)
"Shared", in which case you /don't/ need to use an instance variable, as in
Public Class Faces2
Public Shared ReadOnly Property frown
Get
Return _f
End Get
End Property
Private Shared _f As String = "L"
End Class
....then ...
lblFace.Text = Faces2.frown
If you /really/ want to go the whole hog, (and this /may/ go just a
/little bit/ further than your "very simple program" might want, but...)
Instead of using a helper class (faces) to connect your buttons to the
label and having to "wire-up" all the button events yourself (since all
the "face" buttons work the same way), you could create your /own/
Button class[es], something like this:
Public Class FaceButton
Inherits Button
Public Sub New()
MyBase.New()
End Sub
Public Property Caption() as String
Get
Return _caption
End Get
Set( value as String)
_caption = value
End Set
End Property
Public Property Target() as Label
Get
Return _target
End Get
Set( value as Label)
_target = value
End Set
End Property
Protected Overrides Sub OnClick( _
ByVal e as System.EventArgs )
)
If Not ( _target Is Nothing ) Then
_target.Text = _caption
End if
MyBase.OnClick(e)
End Sub
Private _target As Label
Private _caption As String = "L"
End Class
Class SmileyButton
Inherits FaceButton
Public Sub New()
MyBase.New()
Me.Caption = "J"
End Sub
End Class
Replace the standard buttons with the above class (edit the code VB
tells you never to edit) and initialise them:
[Designer Code]
Private WithEvents smiley As SmileyButton
....
smiley = New SmileyButton
....
Sub Form_Load( ...
Me.smiley.Target = Me.lblFace
End Sub
Now, whenever you click on the smiley button, you update the target label.
Just something to ponder ...
HTH,
Phill W.