473,473 Members | 1,469 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Resize label based on contents

I have a label that displays the output of my program. I want to make the
label very close to the size of the text it contains. The problem is the
text changes.
So, can I dynamically resize the label based on its contents?
Note: the font size changes as well.

Thank you,

Matthew
Nov 21 '05 #1
6 4506
Matthew,

You can try it like this

\\\Most part typed in here so watch typos
Dim g As Graphics = Graphics.FromHwnd(textbox1.Handle)
Dim txtAvgCharWidth As Integer = _
CInt(g.MeasureString("Textbox1.text", textbox1.Font).Width /
Textbox1.lenght)
textbox1.width = mytext.length * txtbAvgCharWidth
////

It is by the way never exact doing this way.

I hope this helps?

Cor
Nov 21 '05 #2
Matthew,

You can try it like this

\\\Most part typed in here so watch typos
Dim g As Graphics = Graphics.FromHwnd(textbox1.Handle)
Dim txtAvgCharWidth As Integer = _
CInt(g.MeasureString("Textbox1.text", textbox1.Font).Width /
Textbox1.lenght)
textbox1.width = mytext.length * txtbAvgCharWidth
////

It is by the way never exact doing this way.

I hope this helps?

Cor
Nov 21 '05 #3
"Matthew" <tu*************@alltel.net> schrieb:
I have a label that displays the output of my program. I want
to make the label very close to the size of the text it contains.
The problem is the text changes.
So, can I dynamically resize the label based on its contents?
Note: the font size changes as well.


Set the label's 'AutoSize' property to 'True'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4
"Matthew" <tu*************@alltel.net> schrieb:
I have a label that displays the output of my program. I want
to make the label very close to the size of the text it contains.
The problem is the text changes.
So, can I dynamically resize the label based on its contents?
Note: the font size changes as well.


Set the label's 'AutoSize' property to 'True'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #5
> Set the label's 'AutoSize' property to 'True'.

You're a genius.

Thanks a million!

Matthew
Nov 21 '05 #6
"Matthew" <tu*************@alltel.net> schrieb:
Set the label's 'AutoSize' property to 'True'.


You're a genius.


In future, check a class's properties/methods in documentation before asking
here :-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #7

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

Similar topics

4
by: Mark | last post by:
Hi, My default page has a table - can anyone tell me how to resize the height of the table to fit the client area of the browser? -- Any help much appreciated... Mark
0
by: Matthew | last post by:
I have a label that displays the output of my program. I want to make the label very close to the size of the text it contains. The problem is the text changes. So, can I dynamically resize the...
3
by: Wenlei Fang | last post by:
Anybody knows how to accomplish this?
1
by: ngreplies | last post by:
I am using a label as a tooltip box because I need to be able to change the background of the box depending on the information it is representing. That aside, I need to be able to auto-size the...
1
by: Mythilisg | last post by:
hi i'm having dropdown list control. i want to activate the visibility of a textbox based on the selected value of dropdown list. The problem is the page gets refresh every time when i choose the any...
2
by: csolomon | last post by:
Happy Hump Day! I was wondering if it would be possible to some how resize my subform based on the number of records it holds. I have a subform that I populate via a non-updatable query. It just...
2
by: manmadhan | last post by:
how to increase the color in a label based on timer
1
by: angelicdevil | last post by:
i cud get it to resize based on width and height by setting them 100%...but now when i reduce the height even thes it alters the size of he site... wat i want to do it based on width of the screen...
3
by: angelicdevil | last post by:
i cud get it to resize based on width and height by setting them 100%...but now when i reduce the height even then it alters the size of the site... wat i want to do it based on width of the...
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
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...
1
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.