PC Review


Reply
Thread Tools Rate Thread

Add controls at runtime (To another form)

 
 
jcrouse
Guest
Posts: n/a
 
      18th Aug 2004
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


 
Reply With Quote
 
 
 
 
Jorge
Guest
Posts: n/a
 
      18th Aug 2004
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
>
>
>.
>

 
Reply With Quote
 
jcrouse
Guest
Posts: n/a
 
      18th Aug 2004
Didn't help!

"Jorge" <(E-Mail Removed)> wrote in message
news:870a01c48522$8b44f130$(E-Mail Removed)...
> 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
> >
> >
> >.
> >



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      18th Aug 2004
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:%23%(E-Mail Removed)...
> Didn't help!
>
> "Jorge" <(E-Mail Removed)> wrote in message
> news:870a01c48522$8b44f130$(E-Mail Removed)...
> > 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
> > >
> > >
> > >.
> > >

>
>



 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      18th Aug 2004
* "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/>
 
Reply With Quote
 
Imran Koradia
Guest
Posts: n/a
 
      18th Aug 2004
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:%23%(E-Mail Removed)...
> Didn't help!
>
> "Jorge" <(E-Mail Removed)> wrote in message
> news:870a01c48522$8b44f130$(E-Mail Removed)...
> > 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
> > >
> > >
> > >.
> > >

>
>



 
Reply With Quote
 
jcrouse
Guest
Posts: n/a
 
      18th Aug 2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:%23%(E-Mail Removed)...
> > Didn't help!
> >
> > "Jorge" <(E-Mail Removed)> wrote in message
> > news:870a01c48522$8b44f130$(E-Mail Removed)...
> > > 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
> > > >
> > > >
> > > >.
> > > >

> >
> >

>
>



 
Reply With Quote
 
jcrouse
Guest
Posts: n/a
 
      18th Aug 2004
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]" <hirf-spam-me-(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> * "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/>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Move controls around form at runtime? Paul Microsoft VB .NET 0 20th Nov 2008 02:02 PM
Adding controls to a form at runtime Todd Huttenstine Microsoft Excel Programming 0 23rd Mar 2006 03:29 PM
hoe can access runtime's form user'controls Mian Mahboob Microsoft C# .NET 1 29th Nov 2005 05:46 PM
Create controls in a form at runtime =?Utf-8?B?UGFudGVsaWFkaXMgQmFiaXM=?= Microsoft Access Form Coding 4 2nd Oct 2004 06:27 PM
How do I find the Components (NOT Controls) on a form at runtime Joe Wirtley Microsoft Dot NET Framework Forms 0 8th Aug 2003 02:30 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:39 PM.