Hi there,

i need to create an array to save the location of labels on the form that are created at runtime. how can i do this please?

thanks

Luke

Your locations are already in the controls collection.

but since they're being created at runtime i don't think it is saved in the controls.collection

Yes it is.

Dim ctrl As New Label
        ctrl.Location = New Point(10, 30)
        ctrl.Visible = True
        ctrl.Text = "The first label"
        ctrl.Name = "Label1"
        Me.Controls.Add(ctrl)
        ctrl = New Label
        ctrl.Location = New Point(150, 30)
        ctrl.Visible = True
        ctrl.Text = "The second label"
        ctrl.Name = "Label2"
        Me.Controls.Add(ctrl)

To get the location:

Dim ctrl As Label = Me.Controls.Item("label1")
        Dim ctrl1 As Label = Me.Controls.Item("label2")
        MessageBox.Show(ctrl.Location.ToString & "|" & ctrl1.Location.ToString)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.