Combining Event Handlers

Post

Posted
Rating:
#1 (In Topic #734)
Avatar
Enthusiast
sadams54 is in the usergroup ‘Enthusiast’
 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.
Online now: No Back to the top

Post

Posted
Rating:
#2
Guru
BruceSteers is in the usergroup ‘Guru’

sadams54 said

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.

Sure just set the Group

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.)
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Guru
cogier is in the usergroup ‘Guru’
Run this code in a Graphical Program. Hopefully it will help you.

Code (gambas)

  1. hButton As Button
  2. Label1 As Label
  3.  
  4. Public Sub AllButtons_Click()
  5.  
  6.   Label1.Text = Last.Name
  7.  
  8.  
  9. Public Sub Form_Open()
  10.  
  11.   ''All this is to add components to the Form
  12.   Dim sButtonNames As String[] = ["btnDoSomething1", "btnDoAnything1", "btnDoSomething2"]
  13.   Dim iLoop As Integer
  14.  
  15.   With Me
  16.     .Height = 215
  17.     .Width = 215
  18.     .Padding = 5
  19.     .Arrangement = Arrange.None
  20.     .Center
  21.  
  22.   For iLoop = 0 To 2
  23.     With hButton = New Button(Me) As "AllButtons"
  24.       .Y = iLoop * 50
  25.       .X = 20
  26.       .W = 175
  27.       .H = 28
  28.       .Name = sButtonNames[iLoop]
  29.       .Text = sButtonNames[iLoop]
  30.     End With
  31.   Next
  32.  
  33.   With Label1 = New Label(Me) As "Label1"
  34.     .Y = iLoop * 50
  35.     .X = 20
  36.     .W = 175
  37.     .H = 28
  38.     .Alignment = Align.Center
  39.     .Font.Bold = True
  40.     .Border = Border.Plain
  41.  
  42.  
  43.  
Online now: No Back to the top
1 guest and 0 members have just viewed this.