473,804 Members | 2,946 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Text Width/Height problem.

Hi folks,
Consider a text containing 200 characters (more or less) including
and/or excluding the CR/LF within. I would like to compute the height
of this text whenever it's width is limited by X pixels! i.e., what's
the height of the mentioned text when it's being automatically word
wrapped within a rectangle of WIDTH pixels? How am I supposed to
calculate the height required to show the message?

TIA,
Mehdi

Jul 22 '06 #1
6 6625
Hello mehdi_mousavi,

I'd recomend you to ask this in microsoft.publi c.dotnet.framew ork.drawing
group
There were several problems, as i remember, with getting font/string height
and spaces between strings because standard font measuring based on the em
box, and some font glyphs are drawned ouside this embox

See there http://groups.google.com/group/micro...+height&qt_g=1

mHi folks,
mConsider a text containing 200 characters (more or less) including
mand/or excluding the CR/LF within. I would like to compute the height
mof this text whenever it's width is limited by X pixels! i.e., what's
mthe height of the mentioned text when it's being automatically word
mwrapped within a rectangle of WIDTH pixels? How am I supposed to
mcalculate the height required to show the message?
mTIA,
mMehdi
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Jul 23 '06 #2
I think you're looking for this :
this.CreateGrap hics().MeasureS tring(string text, Font font, int width);
It has 7 overloads which may be of use, too.
--
cheers
farshad

Jul 23 '06 #3
Well done. Thanks

farshad.A wrote:
I think you're looking for this :
this.CreateGrap hics().MeasureS tring(string text, Font font, int width);
It has 7 overloads which may be of use, too.
--
cheers
farshad
Jul 24 '06 #4
Hi Mehdi,

Assuming that you are writing a WinForms app using the .NET 2.0 framework you can use the TextRenderer class to measure strings in
different formats and with different options.

TextRenderer.Me asureText(...)

In the 1.* frameworks you can measure strings using a method on the Graphics class provided by the Paint method of the target
Control.

Graphics.Measur eString(...)

--
Dave Sexton

"mehdi_mous avi" <me***********@ gmail.comwrote in message news:11******** *************@i 42g2000cwa.goog legroups.com...
Hi folks,
Consider a text containing 200 characters (more or less) including
and/or excluding the CR/LF within. I would like to compute the height
of this text whenever it's width is limited by X pixels! i.e., what's
the height of the mentioned text when it's being automatically word
wrapped within a rectangle of WIDTH pixels? How am I supposed to
calculate the height required to show the message?

TIA,
Mehdi

Jul 25 '06 #5
Hi Dave,

I have been using TextRenderer.Me asureText but the width and height returned
are rounded down. This could lead to missing character on display. I used
g.MeasureString instead as it uses Float instead of integer. Is there
specific code to use to have MeasureText returning the right value ?

Regards,
Sylvain
"Dave Sexton" wrote:
Hi Mehdi,

Assuming that you are writing a WinForms app using the .NET 2.0 framework you can use the TextRenderer class to measure strings in
different formats and with different options.

TextRenderer.Me asureText(...)

In the 1.* frameworks you can measure strings using a method on the Graphics class provided by the Paint method of the target
Control.

Graphics.Measur eString(...)

--
Dave Sexton
Aug 7 '06 #6
Hi Sylvain,

Increase the size of the rectangle being measured. Maybe add a bit of padding to the right edge.

If you get better results from measuring strings with the Graphics object then I suggest you use that method.

The difference is that TextRenderer uses GDI and Graphics uses GDI+.

--
Dave Sexton

"Sylvain Arene" <Sylvain Ar***@discussio ns.microsoft.co mwrote in message
news:B9******** *************** ***********@mic rosoft.com...
Hi Dave,

I have been using TextRenderer.Me asureText but the width and height returned
are rounded down. This could lead to missing character on display. I used
g.MeasureString instead as it uses Float instead of integer. Is there
specific code to use to have MeasureText returning the right value ?

Regards,
Sylvain
"Dave Sexton" wrote:
>Hi Mehdi,

Assuming that you are writing a WinForms app using the .NET 2.0 framework you can use the TextRenderer class to measure strings
in
different formats and with different options.

TextRenderer.M easureText(...)

In the 1.* frameworks you can measure strings using a method on the Graphics class provided by the Paint method of the target
Control.

Graphics.Measu reString(...)

--
Dave Sexton

Aug 7 '06 #7

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

Similar topics

5
1711
by: Lui Ali | last post by:
Hello, Problem: I want to get the whole text between the opening tag <%OPTIONAL%> and the closing tag <%/OPTIONAL%>. The right block is found by (and contains) the placeholder {#xmreisepop_reisepreistext_1_3#}. <%OPTIONAL%> and <%/OPTIONAL%> are not allowed to be inside these tags again.
2
5721
by: Dr. Richard E. Hawkins | last post by:
I've googled around, and asked everyone I know, but I still can't find any reference to anyone else having faced this particular IE bug with floats. I've put a page at http://dochawk.org/sample.html . This was made by stripping out the google ads from the regular pages. It validates as strict 4.01 at http://validator.w3.org. (The google ads drive it nuts!) The main (right) column is made with alternating left and right floats to...
2
2109
by: george.leithead | last post by:
Hi all, I have a very strange problem! In following Web page (which is generated from a CMS System), the navigation to the left 'dissapears' when you roll the mouse over the links? It does not do this in all browsers either. I have found it to happen in IE 7 and the latest patched IE 6. I have tried to find out the reason, but keep finding strange behaviour! You will see at the bottom of the HTML, I have a comment. If you follow...
0
1806
by: VorTechS | last post by:
I'm having a problem with an inherited label, applying text rotation to aligned text. If text rotation is applied to the aligned text, the alignment goes 'nuts'. I can find no logic to what is happening. I've built the following code from several examples on the web, if you remove the rotation then alignment works fine: Imports System.ComponentModel
12
2619
by: tim | last post by:
I am using foldoutmenu 3 and am having problems with viewing my menus in firefox. On my sub3 menus i have more than one line of text in some places. firefox does not recognise that there is more than one line and the text simply overlaps the sub-menus below it. I thought i had got around this by placing empty 'spacers' like so; oFoldMenu.make('sub3','')//spacer unfortunately, i have just viewed the site in IExplorer and it has added...
5
3485
by: iKiLL | last post by:
Hi All, I am trying to Bulid Windows Mobile Forms Control with C# in VS2005 using CF2. On this control A lable is created and some text set for the control. My problem is that i dont know how lond the text is going to be. so i need to set the height and width of the label a cording to the data. un fortunatly i have not been able to find a simple Auto Resize property
4
6056
by: pablorp80 | last post by:
Hello, Here is what I need: I need the focus and the cursor set to a textbox named txtGT, every time no matter if it is the first page load or whether it is a postback. Here is the problem: I am using AJAX and MasterPages as well as an update panel, the textbox is in a panel. I have tried to do it using different java scripts but I can't get it to work because I am not using asp forms, instead I am using Containers. Here is my code:...
1
4228
by: littlealex | last post by:
IE6 not displaying text correctly - IE 7 & Firefox 3 are fine! Need some help with this as fairly new to CSS! In IE6 the text for the following page doesn't display properly - rather than being aligned to the top, along with the slideshow and link buttons, you have to scroll down to see the text - how can I make IE6 display correctly? http://geekarama.co.uk/new_home.html here is the code for new_home.html and following that the CSS...
12
8698
by: Rahaman sharif | last post by:
Hi All, I have some problem in innerHtml. I have the textbox in innerHtml, In the innerHtml textbox was read only. I want make it to enable. if user enter the text that text will be retrieved, so i want to be enable text box. Another one problem is the the innerhtml will be in like popup window. it will automatically closed.i want be whenever i click close button that time only it will close. Please help me. here is the Code <html> ...
0
10561
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10302
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10069
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7608
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6845
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4277
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 we have to send another system
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2976
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.