473,396 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

More Event Handling...

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

Nov 21 '08 #1
2 1284
John Whitworth wrote:
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.
1. Class BitSwitch:

Public Event StatusChanged( _
ByVal sender As Object, ByVal NewStatus As Boolean _
)
In Sub RadioPos_CheckedChanged:

RaiseEvent StatusChanged(Me, _Status)

2. Form:
Before "Next":
AddHandler Bit(CtrlLp).StatusChanged, AddressOf OnStatusChanged

And a new event handler: (an example)

Private Sub OnStatusChanged( _
ByVal sender As Object, ByVal NewStatus As Boolean)

MsgBox(DirectCast(sender, BitSwitch).BitNo & ": " & NewStatus)
End Sub

I want this to be reusable, as I may want to use
the class for several sets of bit settings at one time.
You mean, you need these 8 controls multiple times? Then put them in a
Usercontrol, not directly on the Form. You can add a "Value" property to the
new Usercontrol that returns the calculated value from the 8 bits.
BTW, you don't store all values in Sub New in the usercontrol:

_TrueDesc = TrueDesc
_FalseDesc = FalseDesc
_BitNo = BitNo
And in Sub RadioPos_CheckedChanged, you probably want to update the
displayed text:

If RadioPos.Checked = True Then
_Status = True
BitLabel.Text = _TrueDesc
Else
_Status = False
BitLabel.Text = _FalseDesc
End If

Armin

Nov 21 '08 #2

"Armin Zingler" <az*******@freenet.dewrote in message
news:eX****************@TK2MSFTNGP06.phx.gbl...
If RadioPos.Checked = True Then
_Status = True
BitLabel.Text = _TrueDesc
Else
_Status = False
BitLabel.Text = _FalseDesc
End If
Brilliant! Thanks Armin. That all works perfectly. I should be able to move
on a huge amount now. As you suggest, I do need to move this all into
another control, but I just wanted to get something working first in a form.
I don't need to update BitLabel.Text though, as that is just a numeric
label. The way each BitSwitch looks is:

Bit ?: Here is the true description O O Here is the false
description.

Thanks again - it's much appreciated.

John

Nov 21 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Covad | last post by:
Hi all, For some reason my change() function is only called when the page loads. I'd much rather it gets called when the select changes. Here's the code: window.onload = init; function...
4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
2
by: Marcia Gulesian | last post by:
The following code suppresses the 'enter' key, when run in I.E. 5.5 or later (Windows) but not when run in Safari (Mac) <body onkeypress="javascript:keysuppress(event)" > function...
2
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to...
4
by: hillcountry74 | last post by:
Hi, I'm a newbie and trying to understand event handling in c#. I have understood handling events using delelgate objects. But not this method- "Event handling by overriding the virtual...
3
by: Ashok Kumar K | last post by:
Hi all, Where can I get some insight on using the __hook, __unhook, event_source and event_receiver for specifically COM events. The documentation given in MSDN is very minimal. I have the...
2
by: Paul E. Orman | last post by:
I have a piece of VB code (.NET 1.1 - VB 2003) that loads data from a database through a timer. So the timer is setup and from it I call the procedure that loads the latest records from the...
4
by: mflll | last post by:
I am looking into the different techniques of handling arrays of edit boxes in Java Script. The first program below works fine. However, are there better ways of doing this, where the person...
4
by: reggiestyles | last post by:
Hi, I've got a question about prototype and event handling. I've got several div's (dynamic number) on a page that I want to set as active or inactive (basically, I'm using scriptaculous'...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.