Label Create at Dynamically - Location changed in labels

supun24

New member
Joined
Oct 5, 2009
Messages
4
Programming Experience
3-5
Hi.. I am using Vb 2008. I have created label array in run-time(Dynamically). I have put them in Panel1.
VB.NET:
Dim loc As Integer
        loc = 5
        For i = 1 To 25
            NewLabelMe(i) = New Label
            NewLabelMe(i).Text = "99.99"
            NewLabelMe(i).Size = New Point(65, 35)
            'NewLabelMe(i).Location = New Point(5, loc)
            NewLabelMe(i).Name = "NewLB" & i
            Dim FontName As String = "Microsoft Sans Serif"
            Dim FontSize As Integer = 14
            Dim FS As New Font(FontName, FontSize, FontStyle.Bold)
            NewLabelMe(i).Font = FS
            NewLabelMe(i).TextAlign = ContentAlignment.TopCenter
            NewLabelMe(i).BorderStyle = BorderStyle.Fixed3D
            NewLabelMe(i).Parent = Panel1
            NewLabelMe(i).BringToFront()
            NewLabelMe(i).Anchor = AnchorStyles.Top
            Panel1.Controls.Add(NewLabelMe(i))
            NewLabelMe(i).Left = 5
            NewLabelMe(i).Top = loc
            AddHandler NewLabelMe(i).Click, AddressOf BtnExitOnClick

            loc = loc + 36

        Next
        loc = 5

Some Labels are adding with location change. I have attached my project to your review!!!
Thank You
Supun Silva
 

Attachments

  • Dynamic_Array.zip
    13.9 KB · Views: 30
Last edited by a moderator:
Of course they are adding with the location changed you have
VB.NET:
loc = loc + 36

What is your question?
 
Re:::

My Question is ........

The Cording is working. But When it's generating Labels ....... some times labels are creating in outside of the display area. So we should use scroll bars to see them. so.. When I down the scroll bar .... bottom Labels created with Location changes.
Ex: Normail display area Label Left: 50
Non display area Label Left:55
(I didn't get real Left value, I am telling as I can see)

Thank you,
Supun Silva :rolleyes:
 
I tried getting your files but there are no files contained in the zip. So I made a new project with 1 Form and 1 Panel, made a Label array and used the code you posted in the Load event. Fixed an error that if you had Option Strict On you would have seen.
VB.NET:
  'NewLabelMe(i).Size = New Point(65, 35)
            NewLabelMe(i).Size = New Size(New Point(65, 35))

Anyways.... I ran my project and I got a form with a panel area and a scroll bar. Scrolling down to the bottom it showed all 25 of the labels created in the exact spot that they should have been. None were created outside the display area. Everything seems to be working the way it should, unless you have something else on the form that you have not mentioned.
 
Re::

No same problem having with your code.
I have created this project with vb 2008. I have checked Zip file now. It is working fine. Download it and open Dynamic_Array.sln. from vb 2008. You will see the colation changed in Labels. I have made another command button and inserted following code
VB.NET:
 For i = 1 To 25
            NewLabelMe(i).Left = 5

        Next

Now it is working. All Labels came to same Left value...

Ha ha haaa

It is working... but what is the actual way??

Regards,
Supun Silva
 
Back
Top