[Gambas-user] how to place code into events of an array of buttons?
Gianluigi
bagonergi at gmail.com
Wed Feb 2 11:52:19 CET 2022
Il giorno mer 2 feb 2022 alle ore 11:31 Gianluigi <bagonergi at gmail.com> ha
scritto:
> Hi,
>
> after 10:30 PM the neuron running in my head goes to sleep.
> Therefore, as already suggested by BruceS, the code:
> Private $aButtons[5] As Button
> should be changed to:
> Private $hButton As Button
> and accordingly:
> With $aButtons[n] = New Button(hPan2) As "btns"
> with:
> With $hButton = New Button(hPan2) As "btns"
>
I rewrite all the code because I made a lot of confusion and I apologize:
'---------------------------------
Public Sub Form_Open()
Dim hPan1, hPan2, hPan3 As HBox
Dim aText As String[] = ["A", "B", "C", "D", "E"]
Dim hButton As Button
Me.Margin = True
Me.Arrangement = Arrange.Vertical
With hPan1 = New HBox(Me)
.Expand = True
End With
With hPan2 = New HBox(Me)
.H = 50
.Spacing = True
End With
For n As Byte = 0 To 4
With hButton = New Button(hPan2) As "btns"
.Name = "button" & CStr(n + 1)
.Text = aText[n]
.W = 50
End With
Next
With hPan3 = New HBox(Me)
.Expand = True
End With
End
Public Sub btns_Click()
Dim Index As String = Last.Name
Print "Click " & Last.Text
With FMain[Index]
.Background = Color.Yellow
.Foreground = Color.Red
.Font.Bold = True
End With
End
Public Sub btns_DblClick()
Print "Double click " & Last.Text
End
Public Sub btns_GotFocus()
Print "Got focus " & Last.Text
End
'-------------------------------------------
Regards
Gianluigi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20220202/d29bd1e8/attachment.htm>
More information about the User
mailing list