[Gambas-user] how to place code into events of an array of buttons?

Gianluigi bagonergi at gmail.com
Tue Feb 1 23:16:21 CET 2022


Hi,

maybe I didn't explain well before, the index one is taken from a
Minisini's suggestion, for example using Roberto's code:

Private btns[5] As Button
Private matrice_testo[5] As String

Public Sub Form_Open()

  Dim larghezza As Integer
  Dim altezza As Integer
  Dim larghezza_tasto As Integer
  Dim altezza_tasto As Integer
  Dim n, m As Integer
  Dim offset_verticale As Integer

  larghezza = fmain.Width
  altezza = fmain.height
  larghezza_tasto = larghezza / 10
  altezza_tasto = altezza / 12
  offset_verticale = altezza / 2

  For n = 0 To 4
    btns[n] = New Button(FMain) As "btns"
  Next

  matrice_testo[0] = "A"
  matrice_testo[1] = "B"
  matrice_testo[2] = "C"
  matrice_testo[3] = "D"
  matrice_testo[4] = "E"

  For n = 0 To 4 'prima riga'
    btns[n].Name = "button" & CStr(n + 1)
    btns[n].text = matrice_testo[n]
    btns[n].Left = larghezza_tasto * n
    btns[n].Top = offset_verticale
    btns[n].Height = 50
    btns[n].width = larghezza_tasto
    'btns[n].Show '<-- non serve
  Next

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/20220201/833b12bd/attachment.htm>


More information about the User mailing list