access label from parent panel

Startup

Active Member
Licensed User
Longtime User
I have an array of panels from which I can easily select any panel I want. On each panel I have a label. Is there a way I can access the child label from its parent panel. (I want to access the text on the label). It seems to me there should be some simple code to do this?
 

JonPM

Well-Known Member
Licensed User
Longtime User
You can access the label text directly via LabelName.Text regardless if it is a child of a panel. If it is added through designer you need to generate the declaration
 

Startup

Active Member
Licensed User
Longtime User
You can access the label text directly via LabelName.Text regardless if it is a child of a panel. If it is added through designer you need to generate the declaration
Thanks but I don't know the name of the label. I rotate through a bunch of panels and I want to click on the label on each panel and then get its text to sound out using tts. The problem is I don't know the name of the label but I can identify its parent label from its position in the array of panelviews from which I selected it. If there is a way to get the text in the click event without knowing the name of the label that triggered it that would answer the problem?
 
Last edited:

JonPM

Well-Known Member
Licensed User
Longtime User
Then what Roycefer pointed out is what you need. However this will only work if each panel only contains 1 label. If there are multiple labels then you won't know which one to edit unless you use its name/tag
 

stevel05

Expert
Licensed User
Longtime User
In the label clicked event put:

B4X:
    Dim L As Label = Sender
Log(L.Text)
 

Startup

Active Member
Licensed User
Longtime User
Thanks but I want to be able to get the text from the label
I think you're looking for Panel.GetAllViewsRecursive().[/QUOTE
Then what Roycefer pointed out is what you need. However this will only work if each panel only contains 1 label. If there are multiple labels then you won't know which one to edit unless you use its name/tag

OK. I got it now. My code is now
Dim lv As Label = panels(n).getview(1)
lv.Initialize("")
Dim word As String
lv=Sender
word=lv.Text
Thanks Roycefer and JonPM !!
 

stevel05

Expert
Licensed User
Longtime User
These two lines are unnecessary

B4X:
Dim lv As Label = panels(n).getview(1)
lv.Initialize("")

as when you assign sender to lv, the previous assignment is overwritten, you only need the two lines in my previous post.

In fact, just for clarity, the first line will get the second view from panel (zero based), the Initialize in the second line will overwrite that, then the (correct) assignment of sender to lv will be the one that is left and working.
 

Startup

Active Member
Licensed User
Longtime User
These two lines are unnecessary

B4X:
Dim lv As Label = panels(n).getview(1)
lv.Initialize("")

as when you assign sender to lv, the previous assignment is overwritten, you only need the two lines in my previous post.

In fact, just for clarity, the first line will get the second view from panel (zero based), the Initialize in the second line will overwrite that, then the (correct) assignment of sender to lv will be the one that is left and working.
OK. Gotit. Thanks!
 
Top