473,545 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Graphics.Measur eString - varying results?

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 object created by a Panel, and use the MeasureString() method, I get a different width than when I pass up the procedure a Graphics object created by a PrintDocument.

The procedure is exactly the same, independent of which object called it, so why would the MeasureString width be different? It's not different by a lot, maybe off by 5 or 10, but its still enough to screw up my code...

Yaron
Nov 16 '05 #1
1 4988
Hi,

MeasureString add a little spaces:
FROM MSDN:
The MeasureString method is designed for use with individual strings and
includes a small amount of extra space before and after the string to allow
for overhanging glyphs. Also, the DrawString method adjusts glyph points to
optimize display quality and might display a string narrower than reported
by MeasureString. To obtain metrics suitable for adjacent strings in layout
(for example, when implementing formatted text), use the
MeasureCharacte rRanges method.
Now if the Graphics class passed to the method are different you may get
different results, the one from the Panel refer to the display and the one
from the PrintEventArgs refer to the printer.

My advice is to try the MeasureCharacte rRanges.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Yaron" <Ya***@discussi ons.microsoft.c om> wrote in message
news:CF******** *************** ***********@mic rosoft.com...
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 object created by a Panel, and use
the MeasureString() method, I get a different width than when I pass up the
procedure a Graphics object created by a PrintDocument.
The procedure is exactly the same, independent of which object called it, so why would the MeasureString width be different? It's not different by a
lot, maybe off by 5 or 10, but its still enough to screw up my code...
Yaron

Nov 16 '05 #2

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

Similar topics

1
9565
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 object for which there is only two constructors System.Drawing.Graphics.FromHdc
0
289
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 object created by a Panel, and use the MeasureString() method, I get a different width than when I pass up the procedure a Graphics object created by a...
0
2201
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. the textBox1.Width=268 I typed in 35 'A' with default Font. width retured from MeasureString function is 252
0
1352
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 solution. I would really appreciate it if someone could look at the code below. Label l = new Label();
4
2866
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 SizeF
1
8073
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 = (int)Math.Ceiling(g.MeasureString(this.Text, this.Font, this.Width - this.Padding.Left, StringFormat.GenericDefault).Height); Then override the onPaint and do this...
6
2666
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 string into multiple lines. Is there a way to find out into how many lines the string was split? I am asking because this string is being...
6
10523
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 short string width. What is it I am doing wrong? Here the code I am using: private void MinimizeDgvColumns(DataGridView dgv)
4
4862
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 characters "T", "E", "S", and "T" and then added the resulting values together. The problem is that the two values don't seem to match unless the...
0
7486
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7416
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7676
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. ...
0
7932
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7442
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...
1
5347
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...
0
4965
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...
1
1905
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
1
1032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.