473,373 Members | 1,676 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,373 software developers and data experts.

label that resizes based on text and font

Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #1
4 2524
"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?
You need to use the graphics object and the MeasureString or MeasureText
method (I can't rememeber exactly what it's called)

Feb 21 '06 #2
Are you actually using a Label control? If so you can set the AutoSize
property to true.

--
Tim Wilson
..NET Compact Framework MVP

"JustinC" <ju***********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #3
Hi Justin,
you can set the AutoSize property of the label to true, this way it will
laways resize to fit in the complete string.

Hope that helps
Mark Dawson
--
http://www.markdawson.org
"JustinC" wrote:
Does anyone know how to resize a label so that it's the correct size to
show its text in its font. I've found a handful of ways to figure font
height, but not the overall width of a particular string in a
particular font. Any ideas?

Feb 21 '06 #4
I was able to accomplish what I wanted using the AutoSize, but first
setting a maximum size. This was needed because I had multiple panels
within one larger panel. So the AutoSize caused each control to not
just become to correct width, but to expand to the height of the parent
control which was way too big.

I had to pick a super high number for the maximum width because I don't
want a maximum width, only a max height. Maybe this is something that
can be added in the next .NET framework release ;-)

Feb 22 '06 #5

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

Similar topics

11
by: Peter Larsen [] | last post by:
Hi, I have two questions related to the Label control. How do i prevent the label from expand the canvas into 2 lines (word wrap) ?? At the moment i set AutoSize to false (to prevent the word...
0
by: Kevin McKinley | last post by:
Below i've put the code for a program that i wrote. I need help on lines 384-403. If you run this program you will notice on the first tab when have it produce an answer the $ is surrounded with...
0
by: Guilherme Polo | last post by:
On Wed, Sep 3, 2008 at 8:57 PM, Kevin McKinley <kem1723@yahoo.comwrote: Come on.. "help on lines 384-403", that is not a good way to look for help. You are supposed to post some minimal code that...
6
by: Miro | last post by:
Is there a way to / or a mathematical formula to see if a font size is 'too big' for a label. I have a label that is docked to 'fill' a form, and I want to resize that font based on the width...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.