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

Add controls at runtime (To another form)

P: n/a
I want to add controls (labels) at runtime to a different form. Here is the
code that is being is under a button on form2:

Dim frm1 As New Form1
Dim MyLabel As New Label
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.Top = intTopCounter
MyLabel.ContextMenu = frm1.cmnuLabels
MyLabel.Left = 40
MyLabel.Visible = True
intTopCounter = intTopCounter + 30
frm1.Controls.Add(MyLabel)

However, the labels never show up. What am I missing here.

Thanks,
John
Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hi John

Maybe frm1.Refresh after adding the control.

Kind Regards
Jorge
-----Original Message-----
I want to add controls (labels) at runtime to a different form. Here is thecode that is being is under a button on form2:

Dim frm1 As New Form1
Dim MyLabel As New Label
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.Top = intTopCounter
MyLabel.ContextMenu = frm1.cmnuLabels
MyLabel.Left = 40
MyLabel.Visible = True
intTopCounter = intTopCounter + 30
frm1.Controls.Add(MyLabel)

However, the labels never show up. What am I missing here.
Thanks,
John
.

Nov 21 '05 #2

P: n/a
Didn't help!

"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:87****************************@phx.gbl...
Hi John

Maybe frm1.Refresh after adding the control.

Kind Regards
Jorge
-----Original Message-----
I want to add controls (labels) at runtime to a

different form. Here is the
code that is being is under a button on form2:

Dim frm1 As New Form1
Dim MyLabel As New Label
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.Top = intTopCounter
MyLabel.ContextMenu = frm1.cmnuLabels
MyLabel.Left = 40
MyLabel.Visible = True
intTopCounter = intTopCounter + 30
frm1.Controls.Add(MyLabel)

However, the labels never show up. What am I missing

here.

Thanks,
John
.

Nov 21 '05 #3

P: n/a
John,

You are almost impossible to help.
You put a message in this newsgroup and than start making another one and
people have no time even to answer you and you even do not look to those
answers you get than.

That was the reason I stopped with it, and I think I do this again.

In this case are you creating a new object instance of form1 what never is
showed.

Cor

"jcrouse" <me> schreef in bericht
news:%2******************@TK2MSFTNGP09.phx.gbl...
Didn't help!

"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:87****************************@phx.gbl...
Hi John

Maybe frm1.Refresh after adding the control.

Kind Regards
Jorge
-----Original Message-----
I want to add controls (labels) at runtime to a

different form. Here is the
code that is being is under a button on form2:

Dim frm1 As New Form1
Dim MyLabel As New Label
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.Top = intTopCounter
MyLabel.ContextMenu = frm1.cmnuLabels
MyLabel.Left = 40
MyLabel.Visible = True
intTopCounter = intTopCounter + 30
frm1.Controls.Add(MyLabel)

However, the labels never show up. What am I missing

here.

Thanks,
John
.


Nov 21 '05 #4

P: n/a
This might seem like a stupid question to ask but are you calling
frm1.Show() after you've added the controls?

Imran.

"jcrouse" <me> wrote in message
news:%2******************@TK2MSFTNGP09.phx.gbl...
Didn't help!

"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:87****************************@phx.gbl...
Hi John

Maybe frm1.Refresh after adding the control.

Kind Regards
Jorge
-----Original Message-----
I want to add controls (labels) at runtime to a

different form. Here is the
code that is being is under a button on form2:

Dim frm1 As New Form1
Dim MyLabel As New Label
MyLabel.BackColor = BackColor.Black
MyLabel.ForeColor = ForeColor.White
MyLabel.Text = intTopCounter.ToString
MyLabel.TextAlign = ContentAlignment.MiddleCenter
MyLabel.Top = intTopCounter
MyLabel.ContextMenu = frm1.cmnuLabels
MyLabel.Left = 40
MyLabel.Visible = True
intTopCounter = intTopCounter + 30
frm1.Controls.Add(MyLabel)

However, the labels never show up. What am I missing

here.

Thanks,
John
.


Nov 21 '05 #5

P: n/a
* "jcrouse" <me> scripsit:
I want to add controls (labels) at runtime to a different form. Here is the
code that is being is under a button on form2:

Dim frm1 As New Form1


You are creatung a new instance of 'frm1' instead of using the existing
one. To solve your problem, you will need a reference that points to
the existing instance of the form.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #6

P: n/a
Cor....Sorry if I offended you somehow or broke the forum rules. I thought
these were two seperate issues. One to add a control to a different form and
one to delete a specific control. Sorry man. As far as reposting things you
suggested before, you need to realize that your an extremely advanced user
and some of the suggestions you post are just way above my ability to
understand.

Later,
John

"Cor Ligthert" <no**********@planet.nl> wrote in message
news:OD**************@tk2msftngp13.phx.gbl...
John,

You are almost impossible to help.
You put a message in this newsgroup and than start making another one and
people have no time even to answer you and you even do not look to those
answers you get than.

That was the reason I stopped with it, and I think I do this again.

In this case are you creating a new object instance of form1 what never is
showed.

Cor

"jcrouse" <me> schreef in bericht
news:%2******************@TK2MSFTNGP09.phx.gbl...
Didn't help!

"Jorge" <an*******@discussions.microsoft.com> wrote in message
news:87****************************@phx.gbl...
Hi John

Maybe frm1.Refresh after adding the control.

Kind Regards
Jorge
>-----Original Message-----
>I want to add controls (labels) at runtime to a
different form. Here is the
>code that is being is under a button on form2:
>
> Dim frm1 As New Form1
> Dim MyLabel As New Label
> MyLabel.BackColor = BackColor.Black
> MyLabel.ForeColor = ForeColor.White
> MyLabel.Text = intTopCounter.ToString
> MyLabel.TextAlign = ContentAlignment.MiddleCenter
> MyLabel.Top = intTopCounter
> MyLabel.ContextMenu = frm1.cmnuLabels
> MyLabel.Left = 40
> MyLabel.Visible = True
> intTopCounter = intTopCounter + 30
> frm1.Controls.Add(MyLabel)
>
>However, the labels never show up. What am I missing
here.
>
>Thanks,
>John
>
>
>.
>



Nov 21 '05 #7

P: n/a
Herfried,
Yeah, I kinda figured that out. I had that all straightened out in my
good app but I created a new app from scratch for testing and didn't have
that part in there. I got it now. Thank you for pointing out my error.

John

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:e4**************@tk2msftngp13.phx.gbl...
* "jcrouse" <me> scripsit:
I want to add controls (labels) at runtime to a different form. Here is the code that is being is under a button on form2:

Dim frm1 As New Form1


You are creatung a new instance of 'frm1' instead of using the existing
one. To solve your problem, you will need a reference that points to
the existing instance of the form.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.