Click here to Skip to main content
11,805,604 members (53,610 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: VS2005 VB8.0 VB Visual-Studio , +
how to set text alignment of dynamically added label where i am getting name of label in string variable one label is dynamically added in panel

Dim instance As New Label
Dim stringVariable As String
on form load event ::

instance.Location = New Point(15, 15)
  instance.Size = New Size(60, 30)
  instance.BorderStyle = BorderStyle.FixedSingle
  instance.AutoSize = False
  instance.Text = "LABEL1"
i am getting name by:

for each c as control in Panel1.Controls
but its not possible to

Me.Panel1.Controls(stringVariable).textalign   ??????

it does not show text align property
please help
Posted 30-Nov-12 23:04pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to cast the control to a label:
For Each c As Control In Panel1.Controls
    stringVariable =
    Dim l As Label = TryCast(c, Label)
    If l IsNot Nothing Then
        l.TextAlign = ContentAlignment.MiddleCenter
    End If
Omkaara at 1-Dec-12 5:25am
@OriginalGriff thankyou very much
OriginalGriff at 1-Dec-12 5:27am
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 310
1 Richard Deeming 225
2 Sergey Alexandrovich Kryukov 170
3 Abhinav S 128
4 ppolymorphe 125
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 1 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100