Adding multiple Labels in a Form

im trying to create multiple labels in a form like we create multiple forms with a form how can i do that?
LVL 2
BILAL69Asked:
Who is Participating?
 
Adel87Connect With a Mentor Commented:
Hi,
The following code should do the trick

since you are adding a label then you wont need to access it later on. but if you want to add a remove button also then you would need to add the Labels you are creating to an array to access it later on.

if you need further assistance please let me know.

Regards,
Private Sub Command1_Click()
 
    Dim c As Control
    ' Create and add the new control.
    Set c = Controls.Add("VB.Label", "Text1" & (Controls.Count + 1))
    ' Change the location of the label on the form
    c.Top = (500 * Controls.Count)
    ' Make the new control visible.
    c.Visible = True
    ' Set the initial caption.
    c.Caption = "Hello" & (Controls.Count + 1)
 
    ' Retrieve the text from the new Label.
    MsgBox (c.Caption)
 
End Sub

Open in new window

0
 
viju2008Commented:
can u be more clear with ur question


DO U WANT MULTIPLE LABELS  IN A FORM

THEN ITS AVAILABLE IN THE TOOLBOX  , DRAG AND DROP IT  as many as u want

OR DO U WANT MULITPLE LABELS   AS A CONTROL ARRAY
0
 
BILAL69Author Commented:
yes i want it like i click the button and it generates a new label automatic
0
 
zstapicCommented:
Hm... this is not so easy question...

So you might have two different approaches... first, if the number of labels is finite (known) than you can create them and hide them by default. When you click on your button, it should execute a method which will recognize first hidden label and show it :-)

The bigger problem is if you have INFINITE number of labels to add. Than you'll have to use a container, which will be used to possible scroll down to the last label, and also you'll have to create an instances of label class dynamically...

If I can help you with anything else, just ask :-)
0
 
BILAL69Author Commented:
thnx alot
0
All Courses

From novice to tech pro — start learning today.