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

How do I autosize the TEXT?

I have a box that has a predetermined size. Is there anyway I can automatically size the text to make it the largest it can, while still fitting inside the label's size? I cannot auto size the label, the label needs to stay the same size, I just need to resize the text.

Thanks to all that help!
Dec 31 '09 #1
3 4125
GaryTexmo
1,501 Expert 1GB
Take a look at the Graphics.MeasureString method. Perhaps you can use it to figure out how big your textbox needs to be.
Dec 31 '09 #2
I was trying that, but it said I was missing an event handler. Which Using directive do I need to add? If I read right it said Paint, but I could not find it. Sorry if this is a really simple answer, this is my first application I am trying to build, so I am brand new to C#.

EDIT: Nevermind. I think I found it.
Dec 31 '09 #3
I suppose that the Label's (that contains the text you wanna resize) name is label1.

Expand|Select|Wrap|Line Numbers
  1. System.Drawing.SizeF size = label1.CreateGraphics().MeasureString("the text i wanna measure", label1.Font);
this will return a System.Drawing.SizeF struct object, that has width and height of the text, now check if the width of text is more than label's width
Expand|Select|Wrap|Line Numbers
  1. if(size.Width > label1.Size.Width)
  2. {
  3. //...you can reduce the font size here according to the size of text and label's size.
  4. }
Jan 5 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Harvey | last post by:
Hello: I am trying to use Autosize=true on a long string and it extends off of my form, rather than increasing the number of lines of the Label as the documentation says it should do. Would...
9
by: Kevin Westhead | last post by:
Can anyone confirm whether or not there are any limits imposed on the widths of autosized columns in a list-view. I've found that the autosizing appears to have an upper limit, i.e. it will not...
0
by: OpticTygre | last post by:
How can you autosize a dynamically generated textbox on a form in VS2005 since there is no longer a TextBox.Autosize property? Everything I've read says that it should autosize automatically, but...
1
by: matthewtech | last post by:
In Visual Studio 2005, using Visual Basic, Is there a way to set the autosize property to false as a standard, and change it to true as needed? Or does it always start out as true when a label ...
8
by: Jordi Rico | last post by:
Hi, I've made the next inherited class in Visual Studio 2005: Public Class LabelEx Inherits System.Windows.Forms.Label Sub New() MyBase.New() Me.ForeColor = Color.Black Me.AutoSize = False...
1
by: Patrick Lioi | last post by:
Label label = new Label(); label.Width = 1; label.AutoSize = true; label.Text = "A long string, requiring a width larger than 1."; //At this point, Width is still 1. What am I missing? ...
2
by: =?Utf-8?B?Qm9i?= | last post by:
In VB.Net 2003 and previous versions new labels were created with AutoSize=False. In VB.Net 2005, new labels are created with AutoSize=True. Why was it changed? Is there somewhere in VB.Net 2005...
0
by: Nathan Laff | last post by:
I have a panel set to autosize. Inside it I have a custom label, which changes the height (using measure string) based on the length of the string. (i.e. the label autosizes vertically) this label...
2
by: ChrisNightingale | last post by:
Hi everybody, I have an odd issue which I'm not sure how to resolve. I'm basically implementing a print mechanism which takes a series of controls and reproduces them on a print document. So...
5
by: BillE | last post by:
I am using VB.NET, VS 2005 Add a windows form and in design view: Add a Radiobutton to the windows form Set AutoSize = True for the radiobutton Set the MaximumSize width to 90 for the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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...

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.