Multiple Buttons

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
I created with code 3 Panels with inside a button and a label.
I want when I click the button on the Panel1 write to the Label Panel1 "This is Panel1" and then, if I click the button Panel2 write to the label Panel2 "This is Panel2" and same for the Panel3
How do I code Button_Click?
thank you
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Dim width, height As Int
   'Cree des Panels
   width = 300dip
   height = 80dip
   For y = 0 To 2
         Dim P As Panel
         Dim B1, B2 As Button
         Dim L As Label
         P.Initialize("") 
         P.Color = Colors.Blue
         
         Activity.AddView(P,10dip, 10dip + y * (height + 10dip), width, height)
         MyPanel(y) = P 
         
         B1.Initialize("BtnPre")
         B2.Initialize("BtnPost")
         P.AddView(B1,10dip, 10dip, 50dip, 30dip)
         MyButtonPre(y) = B1
         
         L.Initialize("")
         L.Color = Colors.Red
         L.TextColor = Colors.White
         P.AddView(L,100dip, 50dip, 100dip, 30dip)
         MyLabel(y) = L
      Next
End sub

Sub BtnPre_Click

????????????????????
End Sub
 
Last edited by a moderator:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Something like:
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim width, height As Int
    'Cree des Panels
    width = 300dip
    height = 80dip
    For y = 0 To 2
            Dim P As Panel
            Dim B1, B2 As Button
            Dim L As Label
            P.Initialize("") 
            P.Color = Colors.Blue
            
            Activity.AddView(P,10dip, 10dip + y * (height + 10dip), width, height)
            MyPanel(y) = P 
            
            B1.Initialize("BtnPre")
            B1.Tag = y
            B2.Initialize("BtnPost")
            P.AddView(B1,10dip, 10dip, 50dip, 30dip)
            MyButtonPre(y) = B1
            
            L.Initialize("")
            L.Color = Colors.Red
            L.TextColor = Colors.White
            P.AddView(L,100dip, 50dip, 100dip, 30dip)
            MyLabel(y) = L
        Next
End sub

Sub BtnPre_Click
 Dim b As Button
 b = Sender
 Msgbox("This is panel: " & (b.Tag + 1), "")
End Sub
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank you for the quick response. In fact it is necessary that when I click the button on the Panel1 I send a string in the label of Panel1, and if I click the button Panel2 I send a string to the label Panel2 etc ...
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Please, can you give me an example for my code? This doesn't work.

Sub BtnPre_Click
MyString(0) = "Label11"
MyString(1) = "Label2"
MyString(2) = "Label3"

Dim b As Button
b = Sender
MyLabel(b.tag).Text = Mystring(b.Tag)
End sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…