[Gambas-user] how to write text in indexed list of labels
Charlie Ogier
charlie at cogier.com
Tue Sep 8 17:18:52 CEST 2020
Hi Paolo,
Run the following code in a new Graphical Project. As Benoît said put
the labels in an array.
I hope it helps,
Charlie
***********************************************
hLabel As Label
Label1 As Label
HSplit1 As HSplit
VBox1 As VBox
VBox2 As VBox
ComboBox1 As ComboBox
TextBox1 As TextBox
Button1 As Button
hAllLabels As New Label[]
iList As New Integer[]
Public Sub Button1_Click()
hAllLabels[ComboBox1.Index].Text = TextBox1.Text
End
Public Sub Form_Open()
Dim iLoop As Integer
With Me
.Arrangement = Arrange.Vertical
.Padding = 5
.W = 500
.H = 500
End With
With HSplit1 = New HSplit(Me)
.Expand = True
End With
With VBox1 = New VBox(HSplit1)
.Expand = True
End With
With VBox2 = New VBox(HSplit1)
.Expand = True
.Padding = 2
End With
For iLoop = 0 To 20
With hLabel = New Label(VBox1) As "TheLabels"
.Height = 21
.Width = 200
.Border = Border.Plain
.Alignment = Align.Center
.Text = Format(iLoop, "000")
End With
hAllLabels.Add(hLabel)
iList.Add(iLoop)
Next
With ComboBox1 = New ComboBox(VBox2) As "ComboBox1"
.List = iList
.Height = 28
.Index = 0
End With
With Label1 = New Label(VBox2)
.Height = 28
.Text = "Enter new name for selected Label"
.Alignment = Align.Bottom
End With
With TextBox1 = New TextBox(VBox2) As "TextBox1"
.Height = 28
End With
With Button1 = New Button(VBox2) As "Button1"
.Height = 28
.Text = "Click to change"
End With
HSplit1.Layout = [10, 90]
End
***********************************************
On 06/09/2020 16:58, pinglix via User wrote:
>
> Hi,
>
> I have 200 Label components on a form with name Label1, Label2 ....
> Label200 and I need to change the Text property of one of them through
> an integer index.
>
>
> What is the best way to do it ?
>
> I cannot find a Find() method by name that returns a reference to the
> correct object.
>
> I can set them to the same Group but then what can I do with it ?
>
>
> Thanks,
>
> Paolo
>
>
>
> ----[ http://gambaswiki.org/wiki/doc/netiquette ]----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gambas-basic.org/pipermail/user/attachments/20200908/9c90de3f/attachment.htm>
More information about the User
mailing list