473,406 Members | 2,404 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,406 software developers and data experts.

dynamically creating controls in windows forms

When I create a control dynamically and it grows according to the content,
the control Height property still returns the original default control
height instead of the height after expanding.

How can I get the height of the control (in code) after it grows?

I am building a windows form dynamically, creating controls and placing them
on the form. There can be dozens of controls of all types on the form.
This is for dynamic questionnaires.

The controls can grow, depending on the content. For example, a label
control can expand in height if the content is lengthy.

I am placing the controls on the form by setting the location to a point,
using a Y Position variable that increments with each control by adding the
height of the control to the previous Y position.

However, it seems that if a control expands in height, the Height property
still contains the original height, and so the next control is not placed
low enough on the form.

What is the best way to determine the placement of the controls?

I tried dynamically building a table using the TableLayoutPanel, which
worked fine but the performance was terrible, so I abandoned that approach.

thanks
Bill
Dec 7 '07 #1
8 2784
"BillE" <be****@datamti.comschrieb
When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.

How can I get the height of the control (in code) after it grows?

I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.

The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.

I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each control
by adding the height of the control to the previous Y position.

However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next control
is not placed low enough on the form.

What is the best way to determine the placement of the controls?

I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.

How do the controls "grow"? I can not reproduce the problem. The Height
always returns the Height of the control. Can you post some code?
Armin

Dec 7 '07 #2
In the snippet below, the height of the first control is the initial height
(20), not the height which it grew to to accommodate the long text. The
controls have AutoSize set to True.
Dim lbl1 as New Label
dim xPos as int32 = 100
dim yPos as int32 = 50
'create the first label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos)
lbl1.Text = [a long string forcing the label to increase in size to the
maximum width and a height greater than the original height of 20]

'increase the Y position, so the next label will be placed below the first
label

'******************************
'this returns the initial height, not the increased height
yPos += lbl.Height
'******************************

dim lbl2 as New Label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos) '
lbl2.Text ="whatever"

"Armin Zingler" <az*******@freenet.dewrote in message
news:OB**************@TK2MSFTNGP04.phx.gbl...
"BillE" <be****@datamti.comschrieb
>When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.

How can I get the height of the control (in code) after it grows?

I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.

The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.

I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each control
by adding the height of the control to the previous Y position.

However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next control
is not placed low enough on the form.

What is the best way to determine the placement of the controls?

I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.


How do the controls "grow"? I can not reproduce the problem. The Height
always returns the Height of the control. Can you post some code?
Armin

Dec 7 '07 #3
On Dec 7, 11:18 am, "BillE" <bel...@datamti.comwrote:
In the snippet below, the height of the first control is the initial height
(20), not the height which it grew to to accommodate the long text. The
controls have AutoSize set to True.

Dim lbl1 as New Label
dim xPos as int32 = 100
dim yPos as int32 = 50
'create the first label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos)
lbl1.Text = [a long string forcing the label to increase in size to the
maximum width and a height greater than the original height of 20]
I have tried this before and could never get a Label control's Height
to grow no matter how much text I put in the control's Text property.
The Label control does not have AcceptTab or AcceptReturn properties
and doesn't have a MultiLine property. I could never get it to go
multiline. Does yours?
>
'increase the Y position, so the next label will be placed below the first
label

'******************************
'this returns the initial height, not the increased height
yPos += lbl.Height
'******************************

dim lbl2 as New Label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos) '
lbl2.Text ="whatever"

"Armin Zingler" <az.nos...@freenet.dewrote in message

news:OB**************@TK2MSFTNGP04.phx.gbl...
"BillE" <bel...@datamti.comschrieb
When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.
How can I get the height of the control (in code) after it grows?
I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.
The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.
I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each control
by adding the height of the control to the previous Y position.
However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next control
is not placed low enough on the form.
What is the best way to determine the placement of the controls?
I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.
How do the controls "grow"? I can not reproduce the problem. The Height
always returns the Height of the control. Can you post some code?
Dec 7 '07 #4
If I set AutoSize = True, it grows horizontally and vertically to
accommodate the content.

But the Height property still returns the initial height, not the expanded
height.

Armin, do you see the same behavior? Do you know a way to determine the
height which the control grows to?
<za***@construction-imaging.comwrote in message
news:21**********************************@f3g2000h sg.googlegroups.com...
On Dec 7, 11:18 am, "BillE" <bel...@datamti.comwrote:
>In the snippet below, the height of the first control is the initial
height
(20), not the height which it grew to to accommodate the long text. The
controls have AutoSize set to True.

Dim lbl1 as New Label
dim xPos as int32 = 100
dim yPos as int32 = 50
'create the first label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos)
lbl1.Text = [a long string forcing the label to increase in size to the
maximum width and a height greater than the original height of 20]

I have tried this before and could never get a Label control's Height
to grow no matter how much text I put in the control's Text property.
The Label control does not have AcceptTab or AcceptReturn properties
and doesn't have a MultiLine property. I could never get it to go
multiline. Does yours?
>>
'increase the Y position, so the next label will be placed below the
first
label

'******************************
'this returns the initial height, not the increased height
yPos += lbl.Height
'******************************

dim lbl2 as New Label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos) '
lbl2.Text ="whatever"

"Armin Zingler" <az.nos...@freenet.dewrote in message

news:OB**************@TK2MSFTNGP04.phx.gbl...
"BillE" <bel...@datamti.comschrieb
When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.
>How can I get the height of the control (in code) after it grows?
>I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.
>The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.
>I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each control
by adding the height of the control to the previous Y position.
>However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next control
is not placed low enough on the form.
>What is the best way to determine the placement of the controls?
>I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.
How do the controls "grow"? I can not reproduce the problem. The Height
always returns the Height of the control. Can you post some code?

Dec 7 '07 #5


"BillE" wrote:
If I set AutoSize = True, it grows horizontally and vertically to
accommodate the content.

But the Height property still returns the initial height, not the expanded
height.

Armin, do you see the same behavior? Do you know a way to determine the
height which the control grows to?
<za***@construction-imaging.comwrote in message
news:21**********************************@f3g2000h sg.googlegroups.com...
On Dec 7, 11:18 am, "BillE" <bel...@datamti.comwrote:
In the snippet below, the height of the first control is the initial
height
(20), not the height which it grew to to accommodate the long text. The
controls have AutoSize set to True.

Dim lbl1 as New Label
dim xPos as int32 = 100
dim yPos as int32 = 50
'create the first label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos)
lbl1.Text = [a long string forcing the label to increase in size to the
maximum width and a height greater than the original height of 20]
I have tried this before and could never get a Label control's Height
to grow no matter how much text I put in the control's Text property.
The Label control does not have AcceptTab or AcceptReturn properties
and doesn't have a MultiLine property. I could never get it to go
multiline. Does yours?
>
'increase the Y position, so the next label will be placed below the
first
label

'******************************
'this returns the initial height, not the increased height
yPos += lbl.Height
'******************************

dim lbl2 as New Label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos) '
lbl2.Text ="whatever"

"Armin Zingler" <az.nos...@freenet.dewrote in message

news:OB**************@TK2MSFTNGP04.phx.gbl...

"BillE" <bel...@datamti.comschrieb
When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.

How can I get the height of the control (in code) after it grows?

I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.

The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.

I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each control
by adding the height of the control to the previous Y position.

However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next control
is not placed low enough on the form.

What is the best way to determine the placement of the controls?

I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.

How do the controls "grow"? I can not reproduce the problem. The Height
always returns the Height of the control. Can you post some code?

My experience is the same as Zacks. How are you identifying that the Height
actually changed in your running code?
Dec 7 '07 #6
"BillE" <be****@datamti.comschrieb
If I set AutoSize = True, it grows horizontally and vertically to
accommodate the content.

But the Height property still returns the initial height, not the
expanded height.

Armin, do you see the same behavior? Do you know a way to determine
the height which the control grows to?
In the past, a label with autosize=true was always 1 line high because the
width has been adjusted automatically. Therefore I can't answer this.
Armin

Dec 7 '07 #7
Armin,

The label should grow vertically if the content contains newline characters.
But the height property should reflect this.

Kerry Moorman
"Armin Zingler" wrote:
"BillE" <be****@datamti.comschrieb
If I set AutoSize = True, it grows horizontally and vertically to
accommodate the content.

But the Height property still returns the initial height, not the
expanded height.

Armin, do you see the same behavior? Do you know a way to determine
the height which the control grows to?

In the past, a label with autosize=true was always 1 line high because the
width has been adjusted automatically. Therefore I can't answer this.
Armin

Dec 7 '07 #8
I can visually see that the control has grown - in the code i posted, it is
created with a width of 100 and a height of 20, but when displayed the
control grows vertically to display the full content. However, if i check
for the height of the control in code it is still 20.

"Family Tree Mike" <Fa************@discussions.microsoft.comwrote in
message news:10**********************************@microsof t.com...
>

"BillE" wrote:
>If I set AutoSize = True, it grows horizontally and vertically to
accommodate the content.

But the Height property still returns the initial height, not the
expanded
height.

Armin, do you see the same behavior? Do you know a way to determine the
height which the control grows to?
<za***@construction-imaging.comwrote in message
news:21**********************************@f3g2000 hsg.googlegroups.com...
On Dec 7, 11:18 am, "BillE" <bel...@datamti.comwrote:
In the snippet below, the height of the first control is the initial
height
(20), not the height which it grew to to accommodate the long text.
The
controls have AutoSize set to True.

Dim lbl1 as New Label
dim xPos as int32 = 100
dim yPos as int32 = 50
'create the first label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos)
lbl1.Text = [a long string forcing the label to increase in size to
the
maximum width and a height greater than the original height of 20]

I have tried this before and could never get a Label control's Height
to grow no matter how much text I put in the control's Text property.
The Label control does not have AcceptTab or AcceptReturn properties
and doesn't have a MultiLine property. I could never get it to go
multiline. Does yours?
'increase the Y position, so the next label will be placed below the
first
label

'******************************
'this returns the initial height, not the increased height
yPos += lbl.Height
'******************************

dim lbl2 as New Label
lbl1.AutoSize = True
lbl1.Width = 100
lbl1.Height = 20
lbl1.MaximumSize = New Size (400,1000)
lbl1.MinimumSize = New Size (100,20)
lbl1.Location = New Point (xPos, yPos) '
lbl2.Text ="whatever"

"Armin Zingler" <az.nos...@freenet.dewrote in message

news:OB**************@TK2MSFTNGP04.phx.gbl...

"BillE" <bel...@datamti.comschrieb
When I create a control dynamically and it grows according to the
content, the control Height property still returns the original
default control height instead of the height after expanding.

How can I get the height of the control (in code) after it grows?

I am building a windows form dynamically, creating controls and
placing them on the form. There can be dozens of controls of all
types on the form. This is for dynamic questionnaires.

The controls can grow, depending on the content. For example, a
label control can expand in height if the content is lengthy.

I am placing the controls on the form by setting the location to a
point, using a Y Position variable that increments with each
control
by adding the height of the control to the previous Y position.

However, it seems that if a control expands in height, the Height
property still contains the original height, and so the next
control
is not placed low enough on the form.

What is the best way to determine the placement of the controls?

I tried dynamically building a table using the TableLayoutPanel,
which worked fine but the performance was terrible, so I abandoned
that approach.

How do the controls "grow"? I can not reproduce the problem. The
Height
always returns the Height of the control. Can you post some code?


My experience is the same as Zacks. How are you identifying that the
Height
actually changed in your running code?


Dec 10 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Technical Group | last post by:
Friends, Can anybody help me out by sending a piece of C# code showing how to add an active directory user to a particular user group? If the group does not exist, then create it. Thanks in...
13
by: RCS | last post by:
I have a UI that needs a couple of threads to do some significant processing on a couple of different forms - and while it's at it, update the UI (set textboxes, fill in listviews). I created a...
2
by: macca | last post by:
Hi, I am writing a GUI application. It will have a number of user defined controls( I plan to use/create a user defined control that will output alarm states that the user can also select and...
6
by: Simon Verona | last post by:
I would normally use code such as : Dim Customer as new Customer Dim t as new threading.thread(AddressOf Customer.DisplayCustomer) Customer.CustomerId=MyCustomerId t.start Which would create...
2
by: D Hass | last post by:
Radio Buttons are added to my form During the Load event, the quantity determined by User input. They are placed in pairs on groupboxes with code like this: (edited a bit for brevity) Public...
7
by: mef526 | last post by:
I would like to reference a dynamically created control and I know the name. I would like to use the following: Dim strName as String = "txtControl1" ' This is the ".Name" used when textbox was...
1
by: npaulus | last post by:
Hi, I am trying to dynamically add user controls on to my web form but for some reason my form isnt displaying the user control. form1.cs: using System; using System.Drawing; using...
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
5
by: Chris | last post by:
I have a page with mixture of static and dynamically added controls is there any way of controlling the order which they are added to the page. My submit button (statically added) appears before...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.