By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,285 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,285 IT Pros & Developers. It's quick & easy.

Design Time Label

P: n/a
I'm looking to add a lable control to my windows form when a button is
pressed. The following code does not seem to render the button. How
do I correct this issue?
Dim newLabel As New Label
newLabel.Size = New System.Drawing.Size(272, 16)
newLabel.Name = "NewLabels"
newLabel.BackColor = System.Drawing.Color.Black
newLabel.ForeColor = System.Drawing.Color.Lime
newLabel.Location = New System.Drawing.Point(16, 336)
newLabel.Text = "NewLabels"
newLabel.Visible = True

Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
I used that code with an existing program of mine, and the BringToFront
didn't seem to work. So I moved the BringToFront statement to the end
of your code, and it worked fine. So try to set its z-order after you
add it to your form.


Nov 21 '05 #2

P: n/a
Ok, this worked on a one by one basis.

To take it a step further, how would I create a class of this control
and this add it to a form programmatically?

Nov 21 '05 #3

P: n/a
If you are wanting to create a variation of the Label to customize it
to your program, you would have to create a class that inherits the
Label Class and override its functions. Then, you could use the same
code but instead use your classname instead of Label.

If you were wanting to create one sub that creates a bunch of labels,
you could just use a 'for' statement and make sure to add the
newLabel.BringToFront at the end of your 'for'. Put it in your own sub
so you can specify the parameters. ex: getAnotherLabel(name, text,
posx, posy, w, h, etc...)

for i as integer = 0 to 8
' call the subname where your code is

that would create 9 labels

I don't know if this is what you were looking for, if not please


Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.