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

Determine height of text wrapped in label

If I have a label (AutoSize = false) with more text than can fit it wraps
downwards.
I need to determine how high the label needs to be to fit the whole of the
text in.
I can then put it into a scrolling panel and scroll it like a textbox.
Any ideas on how to do this or a more appropriate method are muchly
appreciated.

Cheers
JB
Nov 16 '05 #1
2 2526
Hi, John

you can use Graphics.MeasureCharacterRanges and Graphics.MeasureString to
get necessary measurements.
MeasureString is useful when you don't need high precision - however for big
strings it is not too good. Some people recommend to use always range
function.

HTH
Alex

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:bl******************@news-server.bigpond.net.au...
If I have a label (AutoSize = false) with more text than can fit it wraps
downwards.
I need to determine how high the label needs to be to fit the whole of the
text in.
I can then put it into a scrolling panel and scroll it like a textbox.
Any ideas on how to do this or a more appropriate method are muchly
appreciated.

Cheers
JB

Nov 16 '05 #2
Thanks Alex
I wanted to try and avoid that as it is quite complicated and the label
control (generally) does a good job of wrapping its text.
I ended up subclassing the label control, adding a new AutoSize enum and
resizing the control using preferredwidth and preferredheight.
It is reasonably accurate except when I have really narrow labels and will
have to do for now.
Cheers
JB
"AlexS" <sa***********@SPAMsympaticoPLEASE.ca> wrote in message
news:OJ**************@TK2MSFTNGP10.phx.gbl...
Hi, John

you can use Graphics.MeasureCharacterRanges and Graphics.MeasureString to
get necessary measurements.
MeasureString is useful when you don't need high precision - however for big strings it is not too good. Some people recommend to use always range
function.

HTH
Alex

"John Baro" <jo***@NOSPAMmesware.com.au> wrote in message
news:bl******************@news-server.bigpond.net.au...
If I have a label (AutoSize = false) with more text than can fit it wraps downwards.
I need to determine how high the label needs to be to fit the whole of the text in.
I can then put it into a scrolling panel and scroll it like a textbox.
Any ideas on how to do this or a more appropriate method are muchly
appreciated.

Cheers
JB


Nov 16 '05 #3

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

Similar topics

11
by: Frostillicus | last post by:
I'm having difficulty creating a menu on the left of a web page where each link appears to have a 4px padding around the edge but I'm trying to do this as a pure unordered list. The "current web...
0
by: Abhijeet Kumar | last post by:
Hi How can i justify align text on Label Control. I am working in C# Desktop application
2
by: David Sworder | last post by:
Hi, A Windows form that I'm developing will have two controls: Label1 and Label2. Both controls are of type Label (go figure). The text of Label1 will not be known until runtime and may change...
9
by: Adam | last post by:
Can someone please help!! I am trying to figure out what a font is? Assume I am working with a fixed font say Courier 10 point font Question 1: What does this mean 10 point font Question 2:...
3
by: Dude | last post by:
Below is the code - it is finding the control, and there is no error, just not assigning the text to the label <asp:DataList id="dlGoals" runat="server" onEditCommand="myListEditHandler"...
0
by: JIM.H. | last post by:
Hello, I am using a label component to show my messages on the screen. When a message text is so big, the label component height is changing, is there any way O can keep it fixed?
1
by: Dave | last post by:
I have a label on a small form. I need to determine if the text in the label fits in the label. My end goal is to reduce the font size of the text in the label until it fits. How can I do this...
2
by: Pucca | last post by:
How do I make the TreeView control's node text (or label) editable when user click twice on it? (Not double click). It's like the explorer on our computer drives. The directory tree label...
8
by: Jonathan Sachs | last post by:
I'm trying to compose a list of items, each of which consists of text that wraps around a picture at the left margin. The examples I have seen tell me to do it like this: <p><img src="xxxx.jpg"...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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
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...

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.