I'm tying myself up in knots again here.
I think my query is a little different from the previous Event handling one,
so have started a new thread.
In VB2008, I want a reusable control, which can effectively show (and set)
bit settings with true/false descriptions for each byte.
Eventually, I want to group each byte into a panel, so I can treat them as a
whole (and then probably put several panels into a tab control, so that a
3-byte config parameter can be worked on within one form), but for the
moment, I have just added 8 "BitSwitch" controls into a form, the class &
code being as follows:
Public Class BitSwitch
Private _Status As Boolean
Private _TrueDesc As String
Private _FalseDesc As String
Private _BitNo As Integer
Public Sub New(ByVal Status As Boolean, ByVal BitNo As Integer, Optional
ByVal TrueDesc As String = "True", Optional ByVal FalseDesc As String =
"False")
Me.InitializeComponent()
Me.RadioPos.Text = TrueDesc
Me.RadioNeg.Text = FalseDesc
Me.BitLabel.Text = "Bit " & BitNo.ToString & ":"
If Status = True Then
RadioPos.Checked = Enabled
Else
RadioNeg.Checked = Enabled
End If
End Sub
Public Property BitNo() As Integer
Get
Return _BitNo
End Get
Set(ByVal value As Integer)
_BitNo = value
End Set
End Property
Public Property Status() As Boolean
Get
Return _Status
End Get
Set(ByVal value As Boolean)
_Status = value
End Set
End Property
Public Property TrueDesc() As String
Get
Return _TrueDesc
End Get
Set(ByVal value As String)
_TrueDesc = value
End Set
End Property
Public Property FalseDesc() As String
Get
Return _FalseDesc
End Get
Set(ByVal value As String)
_FalseDesc = value
End Set
End Property
Private Sub RadioPos_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles RadioPos.CheckedChanged
If RadioPos.Checked = True Then
_Status = True
Else
_Status = False
End If
' I'm pretty sure I need to fire off my custom event here!!
End Sub
End Class
Public Class TestForm
Private Sub TestForm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
Dim Bit(7) As BitSwitch
Dim CtrlLp As Integer
For CtrlLp = 7 To 0 Step -1
Bit(CtrlLp) = New BitSwitch(True, CtrlLp, "True " & CtrlLp.ToString, "False
" & CtrlLp.ToString)
Bit(CtrlLp).Location = New Point(0, (7 - CtrlLp) * 45)
Me.Controls.Add(Bit(CtrlLp))
Next
End Sub
End Class
So TestForm populates with 8 BitSwitches, and they all show their true/false
descriptions properly. What I want to do is have a custom event that is
fired whenever the state of any of the radio switches is changed in one of
the 8 BitSwitches. Basically, I want an event in TestForm that can
recalculate the byte value based on the settings of the 8 BitSwitches. I
want this to be reusable, as I may want to use the class for several sets of
bit settings at one time.
I looked in the online examples, and started playing with Delegates etc, but
got in a right royal mess! :-) I may well be overengineering this, but I'm
sure this is not simply something that I can do with the GUI.
Thanks
John