473,785 Members | 2,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.InitializeCo mponent()

Me.RadioPos.Tex t = TrueDesc

Me.RadioNeg.Tex t = FalseDesc

Me.BitLabel.Tex t = "Bit " & BitNo.ToString & ":"

If Status = True Then

RadioPos.Checke d = Enabled

Else

RadioNeg.Checke d = 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_Checke dChanged(ByVal sender As Object, ByVal e As
System.EventArg s) Handles RadioPos.Checke dChanged

If RadioPos.Checke d = 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(B yVal sender As Object, ByVal e As
System.EventArg s) 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).Loc ation = 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 1297
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_Checke dChanged:

RaiseEvent StatusChanged(M e, _Status)

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

And a new event handler: (an example)

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

MsgBox(DirectCa st(sender, BitSwitch).BitN o & ": " & 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_Checke dChanged, you probably want to update the
displayed text:

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

Armin

Nov 21 '08 #2

"Armin Zingler" <az*******@free net.dewrote in message
news:eX******** ********@TK2MSF TNGP06.phx.gbl. ..
If RadioPos.Checke d = 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
20701
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 init() {
4
12582
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)"; document.getElementById('myelement') = new Function("myfnc(param1,param2,param3)");
2
2033
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 keysuppress(e) { if (e.type=="keypress" && e.keyCode=="13") { event.returnValue=false
2
2104
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 parse then vb due to braces) whereas you look for Handles keyword after method sig, but before opening brace of the method. compiler would implicitly build event handling code for all typed constructions, ie, any variables instances constructed...
4
1754
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 protected method of the base class". Can someone please explain this with a sample code? Thanks a lot.
3
2081
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 following scenario Server (COM event source) is written in VC++ 6.0 using ATL (event interfaces can be either dispinterface / IDispatch based) Client (COM event receiver) is written in VC++ 2003 using attributed programming and unified event handling
2
2137
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 database. This works fine. However, I attempt to notify the user when data accesses occur. The way I attempt to accomplish this is by changing the background color of a label on the form the user is looking at. I use red for when the database is...
4
9698
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 writing the JavaScript doesn't have to pass the index in the "onChange" event name. I thought that one might be able to use "this.value" or compare this as
4
2096
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' Effects to set Opacity to 1 for the active div and 0.5 for the inactive ones). Using prototype's event handling, I can see two ways to get this done:
0
9647
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9485
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10098
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9958
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8986
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6743
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4058
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.