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

Graphics.MeasureString

Dom
I have a user control and I do the following:

Graphics g = this.CreateGraphics();
SizeF s = g.MeasureString (MyText, MyFont);

This works fine as long as MyText is not a string of blanks. If it
is, then I always get the same s.Width values. It doesn't matter if
the string is 1 blank or 5 blanks. It doesn't even matter what the
font is. It is always the same.

Any reason?

Aug 16 '07 #1
2 2545
On 16 Aug, 15:58, Dom <dolivas...@gmail.comwrote:
I have a user control and I do the following:

Graphics g = this.CreateGraphics();
SizeF s = g.MeasureString (MyText, MyFont);

This works fine as long as MyText is not a string of blanks. If it
is, then I always get the same s.Width values. It doesn't matter if
the string is 1 blank or 5 blanks. It doesn't even matter what the
font is. It is always the same.

Any reason?
use the overload that takes a stringformat. The intellisense will
explain all :)

new StringFormat(StringFormatFlags.MeasureTrailingSpac es)

Aug 16 '07 #2
Dom
On Aug 16, 11:00 am, DeveloperX <nntp...@operamail.comwrote:
On 16 Aug, 15:58, Dom <dolivas...@gmail.comwrote:
I have a user control and I do the following:
Graphics g = this.CreateGraphics();
SizeF s = g.MeasureString (MyText, MyFont);
This works fine as long as MyText is not a string of blanks. If it
is, then I always get the same s.Width values. It doesn't matter if
the string is 1 blank or 5 blanks. It doesn't even matter what the
font is. It is always the same.
Any reason?

use the overload that takes a stringformat. The intellisense will
explain all :)

new StringFormat(StringFormatFlags.MeasureTrailingSpac es)
Thanks. Worked like a charm!!

Dom

Aug 16 '07 #3

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

Similar topics

1
by: Paul Hoad | last post by:
I'm trying to use MeasureString() to determine the length in pixels of a string However to do I need a System.Drawing.Graphics object to do this I need to create a System.Drawing.Graphics...
1
by: Yaron | last post by:
Hi, I made a procedure which receives a Graphics parameter, and with that Graphics parameter, performs various things. The area of confusion here is that when I pass the procedure a Graphics...
0
by: keith | last post by:
I did a test typing characters until fill out whole textbox (single line). Then I chcked width of this string in paint event e.Graphics.MeasureString(textBox1.Text,textBox1.Font).Width e.g....
0
by: Meetali Goel | last post by:
Hi all, I can't determine why I keep getting "NotSupportedException" when g.MeasureString() is called in the following code (.NET CE). I have spent several hours but I cant seem to find the...
3
by: max | last post by:
Is there a method in the Graphic to wrap a string into a rectangle? If so is there a way to specify the width and let a Graphics method determine how much vertical space is required? I tried using...
4
by: Anil Gupte | last post by:
I copied the following almost directly from http://msdn2.microsoft.com/en-us/library/6xe5hazb.aspx Dim instance As Graphics Dim text As String 'Dim strfont As Font Dim returnValue As...
1
by: Nathan Laff | last post by:
I have a custom label, that as the width changes, the height will change to fit all the text in the label... I use to do this like this... int newHeight =...
6
by: Dilip | last post by:
Howdy Folks I have a display where the Graphics.DrawString function is called to display something. Since the text seems to be larger than its bounding rectangle, the call basically splits the...
6
by: Rainer Queck | last post by:
Hello NG, I am trying to adjust the column width of a DataGridView to the Text in its column header. To do this I am using the Graphics.MeasureString method. Unfortunatly I alway get a too...
4
nukefusion
by: nukefusion | last post by:
I'm having trouble using MeasureCharacterRanges. If I use it to get the width of the string "TEST" I would expect to get the same width as I would if I used it to get the individual widths of the...
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: 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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.