Sorry to be asking so much however I am wondering if there is a way to make several controls all fire the same handler.
For example, I have 3 buttons named... btnDoSomething1 btnDoAnything1 btnDoSomething2
I want them all to fire the event btnDoSomething1_click rather than each have it's own click event.
Combining Event Handlers
- BruceSteers
- Posts: 1570
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Combining Event Handlers
Sure just set the Groupsadams54 wrote: ↑Tuesday 31st August 2021 11:09pm Sorry to be asking so much however I am wondering if there is a way to make several controls all fire the same handler.
For example, I have 3 buttons named... btnDoSomething1 btnDoAnything1 btnDoSomething2
I want them all to fire the event btnDoSomething1_click rather than each have it's own click event.
If they all have the Group "MyButts"
then MyButts_Click will be useable.
(the IDE will auto-goto event handler on double clicking if a group is set.)
If at first you don't succeed , try doing something differently.
BruceS
BruceS
- cogier
- Site Admin
- Posts: 1125
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Combining Event Handlers
Run this code in a Graphical Program. Hopefully it will help you.
hButton As Button
Label1 As Label
Public Sub AllButtons_Click()
Label1.Text = Last.Name
End
Public Sub Form_Open()
''All this is to add components to the Form
Dim sButtonNames As String[] = ["btnDoSomething1", "btnDoAnything1", "btnDoSomething2"]
Dim iLoop As Integer
With Me
.Height = 215
.Width = 215
.Padding = 5
.Arrangement = Arrange.None
.Center
End With
For iLoop = 0 To 2
With hButton = New Button(Me) As "AllButtons"
.Y = iLoop * 50
.X = 20
.W = 175
.H = 28
.Name = sButtonNames[iLoop]
.Text = sButtonNames[iLoop]
End With
Next
With Label1 = New Label(Me) As "Label1"
.Y = iLoop * 50
.X = 20
.W = 175
.H = 28
.Alignment = Align.Center
.Font.Bold = True
.Border = Border.Plain
End With
End