473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Add controls at runtime (To another form)

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
7 1519
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
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
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
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
* "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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: TD | last post by:
This is the code under a command button - Dim ctl As Control For Each ctl In Me.Controls If ctl.BackColor <> RGB(255, 255, 255) Then ctl.BackColor = RGB(255, 255, 255) End If Next ctl
0
by: Sinisa | last post by:
I have a Windows form which has multiple groups of the same window controls. I wanted to create a control class that has the standard controls in one. something like: public class Sensor :...
2
by: Jon Pope | last post by:
I'm programmatically adding controls to a form. The issue I'm seeing is that I can see the controls lay themselves out on the form during runtime. I'd rather not see this. I've used the...
1
by: Markus Wildgruber | last post by:
Hi! Is there a way to determine the (tab-)order of controls at runtime? My goal is to get a unique number for each control on a form that could deal as a priority value for that control. The...
2
by: Alex SFT | last post by:
I know this is silly question, but.. when I started a new project and putted simple controls (text, label, button) on form (WebForm1.aspx) and after that when I'm doing "View in Browser" they're...
14
by: Jan Nielsen | last post by:
Hi In Microsoft Access it is possible to write code like this Sub test() DoCmd.OpenForm "TestForm", acDesign Dim a As Control For Each a In Forms("TestForm").Controls Do stuff Next End Sub
3
by: Chris Calzaretta | last post by:
I need to create a form from this web service http://24.163.239.122/wsprojecttrackerobjects/wsprojecttrackerobjects.asmx if you call getloginscreen there is a field called screendescription that...
4
by: helpful sql | last post by:
Hi, Are there any cool controls that would allow me to automatically resize and repositions controls on my form when the form is resized at runtime? Thanks in advance.
2
by: Steve | last post by:
This is a weird one. I have a series of "SmartParts" which are CAB (Composite Application Block) Views which are finally just UserControls (99% of the time) Anyway, I layout my UserControl in...
3
by: garyusenet | last post by:
I want to disable all controls on form barring two buttons. I have about 20 controls. Is there a way I can reference all controls on the form in one go? So I could then do something like.. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.