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

Gianluigi bagonergi at gmail.com
Wed Feb 2 00:01:57 CET 2022


Roberto,

I agree with those who suggested to use the containers that are the real
strength of Gambas.
Same example as yours with containers:

Private $aButtons[5] As Button

Public Sub Form_Open()

  Dim hPan1, hPan2, hPan3 As HBox
  Dim aText As String[] = ["A", "B", "C", "D", "E"]

  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 $aButtons[n] = 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/f6706e67/attachment-0001.htm>


More information about the User mailing list