Sender BringToFront difficulty

enonod

Well-Known Member
Licensed User
Longtime User
I am trying to avoid keeping an array to record the existence of transparent Labels which overlay Rects, to give the Rects a Click.

In the common Click Sub I use Sender to return the Label.

Outside the Click Sub I later need to bring the label to the front of the underlying Rect which was by now redrawn, probably on top of the Label.

I thought that if I saved the Sender Label in the main Panel.Tag before leaving the Click sub, I could retrieve it later and BringToFront.
It did not work.
This is the only reference needed to the Labels outside the Click sub.
Is there any other way please?
B4X:
Dim lb as Label

Sub A_Click
    Dim snd as Label
    snd=Sender
    ...
    pnl.Tag=snd
End Sub
'Problem... cannot get a click after underlying Rect redrawn.
'This did not work but did allow colour change but no click 'Probably because it is now a different Label??

       lb.Initialize("A")      'Am I putting a new label over the old?
   lb=pnl.Tag
   lb.Color= Colors.LightGray 
   lb.BringToFront
 
Last edited:

MLDev

Active Member
Licensed User
Longtime User
Remove snd declaration from the A_Click sub and declare snd as a global:

B4X:
Sub Globals
   Dim snd as Label
End Sub

Sub A_Click
   snd=Sender
   ...
End Sub

Then you can do this:

B4X:
lb=snd
lb.Color= Colors.LightGray
lb.BringToFront
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thank you so much MLDev, I have been tearing hair out.
Your suggestion certainly means I only have the current Label stored Globally.
 
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
However...
unfortunately still no click once I get to the 'lb' sequence, even with an invalidate.
 
Upvote 0

MLDev

Active Member
Licensed User
Longtime User
However...
unfortunately still no click once I get to the 'lb' sequence, even with an invalidate.

:sign0013: I thought that would work for you. I wrote this code to test if I could save the sender label in snd then BringToFront later. When you click under the button the labels will flip being in front unless you click on the button. Then the last label saved in snd will be in front. Could you post some code to help me see what you're doing?

B4X:
Sub Globals
   Dim btn1 As Button
   Dim lblOne As Label
   Dim lblTwo As Label
   Dim snd As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   btn1.Initialize("btn1")
   Activity.AddView(btn1, 45%x, 0, 10%x, 10%y)
   btn1.Text = "Same"
   lblOne.Initialize("lblOne")
   lblTwo.Initialize("lblTwo")
   Activity.AddView(lblOne, 0, 10%y, 100%x, 100%y)
   Activity.AddView(lblTwo, 0, 10%y, 100%x, 100%y)
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub lblOne_Click
   lblOne.Text = "lblOne clicked"
   snd = Sender
   lblTwo.BringToFront
End Sub

Sub lblTwo_Click
   lblOne.Text = "lblTwo clicked"
   snd = Sender
   lblOne.BringToFront
End Sub

Sub btn1_Click
   snd.BringToFront
End Sub
 
Last edited:
Upvote 0

enonod

Well-Known Member
Licensed User
Longtime User
Thanks for your continued input. Unfortunately your example does not reproduce the situation. If a Rect had a Click event I wouldn't have a problem. The Label is only to provide that. Having all Labels probably presents a memory use increase plus I have to Tag the colours to read them, so back to Rects.
I have tried to extract the relevant code from the rest to illustrate but it is too difficult. I can perhaps describe it better.
I produce a small grid of coloured Rectangles.

On top of one I place a Label that is transparent.
It is Dim'd locally and thus not saved in an Array or directly referenceable except with Sender. This is essential.
At your suggestion snd to receive Sender is now a Global Label.

Upon clicking the Label, the colour of the Rectangle under the Label is changed and the Rect is redrawn and invalidated. The new colour is visible through the Label.

A second Click gets no response, 'presumably' because the label is below the Rect??
I need to use Global snd in the main code to bring the Label forward but it does not work, because I still get no Click.
However to test using Sender (snd) I used it to change the Label colour and the Tag content and that worked fine. Just no Click.

B4X:
'c,r are Global row col parameters. brk the overlaying Label. sEvent "Yes"
Sub liveB(c,r As Byte, sEvent As String)
   Dim brk As Label
   Dim aTag(2) As Byte
   brk.Initialize(sEvent)
   aTag(0)=c : aTag(1)=r
   brk.Tag=aTag
   brk.Color=Colors.Transparent
   pnl.AddView(brk,(c+1)+c*kCellwh,(r+1)+r*kCellwh,kCellwh,kCellwh)
End Sub

Sub Yes_Click
  Dim aPos(2) As Byte
   snd=Sender
   aPos=snd.Tag
   ...
End Sub

somewhere in the main code that changes the Rect colours I need...
snd.BringToFront to actually work after redrawing the Rect.
 
Last edited:
Upvote 0
Top