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

dynamically creating controls in windows forms

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a


"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

P: n/a
"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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.