Indexing Panels

hackhack

Active Member
Licensed User
Longtime User
If I make an array of panels

Like

B4X:
Dim stuff(5) As Panel

stuff(i).Initialize("stuff")
stuff(i).Color=Colors.black

Is there some way I can make one stuff_click to process all panels, or do i have to make stuff1_click, stuff2_click etc for each one?
 
Last edited:

warwound

Expert
Licensed User
Longtime User
Hi.

The EventName you initialise your Panel with dictates the name of the Sub called.

So you're initialising your Panels with an EventName of stuff and a click on any Panel will call Sub stuff_Click.
If you set each Panel's Tag to a unique index then you can detect which Panel has been clicked in that Sub:

B4X:
Sub stuff_Click
   Dim ClickedPanel As Panel
   Dim ClickedPanelTag As Int
   ClickedPanel=Sender
   ClickedPanelTag=ClickedPanel.Tag
   ' do stuff
End Sub

Martin.
 
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
Hi.

The EventName you initialise your Panel with dictates the name of the Sub called.

So you're initialising your Panels with an EventName of stuff and a click on any Panel will call Sub stuff_Click.
If you set each Panel's Tag to a unique index then you can detect which Panel has been clicked in that Sub:

Yeah, I knew all that - except that there is something called "Sender" - thanks :)
 
Upvote 0

hdtvirl

Active Member
Licensed User
Longtime User
HackHack

Did you not answer your question yourself in your first post on this thread !

The sender indentifies which control Panel(1), Panel(2) etc called the subroutine,
as Warwound documented

Sub stuff_Click
Dim ClickedPanel As Panel
Dim ClickedPanelTag As Int
ClickedPanel=Sender
ClickedPanelTag=ClickedPanel.Tag
' do stuff
End Sub

so if panel(1) clicked called the subroutine and it tag was '1' then
ClickedPanel.Tag would = '1' and so on.

I hope this helps you.

Regards

BOB
 
Last edited:
Upvote 0

hackhack

Active Member
Licensed User
Longtime User
HackHack

Did you not answer your question yourself in your first post on this thread !

No, because I didn't know which of the panels called the event, and so had no way of checking for tags.

But then warwound told me about "sender"
 
Upvote 0
Top