.NETGURU
MeasureString method
Messages   Related Types
This message was discovered on ASPFriends.com 'ngfx-drawing' list.


xico
Hi all,

I'm trying to get the actual size of a string using a specific font. To
acomplish this task I use the Graphics.MeasureString that returns a Size
object. The problem is that the Size object returned is bigger that the
string, rather than the exact string size.

And this difference isn't the same if I change the font facename. Does
anybody is having the same kind of problem?

Cheers,
- xico -

Reply to this message...
 
    
Ollie Cornes

when you say "bigger" do you mean vertically, horizontally, or both?

Ollie

----- Original Message -----
From: "xico" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 12:19 PM
Subject: [ngfx-drawing] MeasureString method

[Original message clipped]

Reply to this message...
 
    
Chris Kinsman
I am using MeasureString and it is working just fine:

I use it like:

SizeF c =3D (SizeF) g.MeasureString(iCount.ToString(), base.Font);

where g is the graphics object, iCount.ToString() represents the string
I am measuring and base.Font is the font to use to measure it.

-----Original Message-----
From: xico [mailto:Click here to reveal e-mail address]
Sent: Tuesday, November 27, 2001 4:19 AM
To: ngfx-drawing
Subject: [ngfx-drawing] MeasureString method

Hi all,

I'm trying to get the actual size of a string using a specific font. To
acomplish this task I use the Graphics.MeasureString that returns a Size
object. The problem is that the Size object returned is bigger that the
string, rather than the exact string size.

And this difference isn't the same if I change the font facename. Does
anybody is having the same kind of problem?

Cheers,
- xico -

| [ngfx-drawing] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
xico
Hi Chris,

I don't know why you use it, but I need it to align vertically a text with a
line previous drawn.
I doesn't align properly, so I have to subtract 3 from the returned size
height.

- xico -

----- Original Message -----
From: "Chris Kinsman" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 1:21 PM
Subject: [ngfx-drawing] RE: MeasureString method

I am using MeasureString and it is working just fine:

I use it like:

SizeF c = (SizeF) g.MeasureString(iCount.ToString(), base.Font);

where g is the graphics object, iCount.ToString() represents the string
I am measuring and base.Font is the font to use to measure it.

-----Original Message-----
From: xico [mailto:Click here to reveal e-mail address]
Sent: Tuesday, November 27, 2001 4:19 AM
To: ngfx-drawing
Subject: [ngfx-drawing] MeasureString method

Hi all,

I'm trying to get the actual size of a string using a specific font. To
acomplish this task I use the Graphics.MeasureString that returns a Size
object. The problem is that the Size object returned is bigger that the
string, rather than the exact string size.

And this difference isn't the same if I change the font facename. Does
anybody is having the same kind of problem?

Cheers,
- xico -

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
Rick Hodder
Could you post code so that we can see how you are using it?

-----Original Message-----
From: xico [mailto:Click here to reveal e-mail address]
Sent: Tuesday, November 27, 2001 2:58 PM
To: ngfx-drawing
Subject: [ngfx-drawing] RE: MeasureString method

Hi Chris,

I don't know why you use it, but I need it to align vertically a text with a
line previous drawn.
I doesn't align properly, so I have to subtract 3 from the returned size
height.

- xico -

----- Original Message -----
From: "Chris Kinsman" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 1:21 PM
Subject: [ngfx-drawing] RE: MeasureString method

I am using MeasureString and it is working just fine:

I use it like:

SizeF c = (SizeF) g.MeasureString(iCount.ToString(), base.Font);

where g is the graphics object, iCount.ToString() represents the string
I am measuring and base.Font is the font to use to measure it.

-----Original Message-----
From: xico [mailto:Click here to reveal e-mail address]
Sent: Tuesday, November 27, 2001 4:19 AM
To: ngfx-drawing
Subject: [ngfx-drawing] MeasureString method

Hi all,

I'm trying to get the actual size of a string using a specific font. To
acomplish this task I use the Graphics.MeasureString that returns a Size
object. The problem is that the Size object returned is bigger that the
string, rather than the exact string size.

And this difference isn't the same if I change the font facename. Does
anybody is having the same kind of problem?

Cheers,
- xico -

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

| [ngfx-drawing] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp = JOIN/QUIT
| http://www.asplists.com/search = SEARCH Archives

Reply to this message...
 
    
xico
Rick,

If I remove the -3 in line 11 the string is draw above the line draw in line
23.

1 ...
2
3 Font font = new Font(FontName, mark.FontSize);
4
5 SizeF size = Graphics.MeasureString(mark.Description, font);
6 float fPosY = GetPosY(mark.Value);
7 float fPosX = DrawArea.Left - (2 + size.Width);
8
9 Brush brush = new SolidBrush(mark.Color);
10
11 Graphics.DrawString(mark.Description, font, brush, fPosX, fPosY -
(size.Height - 3));
12
13 font.Dispose();
14 brush.Dispose();
15
16 if (mark.ShowLine)
17 {
18 int nLineX = DrawArea.Left;
19
20 Pen pen = new Pen(mark.Color, 1);
21 pen.DashStyle = mark.LineStyle;
22
23 Graphics.DrawLine(pen, nLineX, fPosY, DrawArea.Right, fPosY);
24
25 pen.Dispose();
26 }
27 ...

----- Original Message -----
From: "Rick Hodder" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 3:56 PM
Subject: [ngfx-drawing] RE: MeasureString method

[Original message clipped]

Reply to this message...
 
    
Chris Kinsman
Well by subtracing the size from fPosY of course it would be above the
line drawn at fPosY.

this should draw

Description
----------------

I think. Are you saying you want:

----------------
Description

If so it should be fPosY + the height of the line you drew + any margin.

-----Original Message-----
From: xico [mailto:Click here to reveal e-mail address]
Sent: Tuesday, November 27, 2001 12:37 PM
To: ngfx-drawing
Subject: [ngfx-drawing] RE: MeasureString method

Rick,

If I remove the -3 in line 11 the string is draw above the line draw in
line
23.

1 ...
2
3 Font font =3D new Font(FontName, mark.FontSize);
4
5 SizeF size =3D Graphics.MeasureString(mark.Description, font);
6 float fPosY =3D GetPosY(mark.Value);
7 float fPosX =3D DrawArea.Left - (2 + size.Width);
8
9 Brush brush =3D new SolidBrush(mark.Color);
10
11 Graphics.DrawString(mark.Description, font, brush, fPosX, fPosY -
(size.Height - 3));
12
13 font.Dispose();
14 brush.Dispose();
15
16 if (mark.ShowLine)
17 {
18 int nLineX =3D DrawArea.Left;
19
20 Pen pen =3D new Pen(mark.Color, 1);
21 pen.DashStyle =3D mark.LineStyle;
22
23 Graphics.DrawLine(pen, nLineX, fPosY, DrawArea.Right, fPosY);
24
25 pen.Dispose();
26 }
27 ...

----- Original Message -----
From: "Rick Hodder" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 3:56 PM
Subject: [ngfx-drawing] RE: MeasureString method

[Original message clipped]

a
[Original message clipped]

| [ngfx-drawing] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngbeta.asp =3D JOIN/QUIT
| http://www.asplists.com/search =3D SEARCH Archives

Reply to this message...
 
    
Ollie Cornes

The height returned from MeasureString will allow for characters with
different positioning on the text line. For example a P character will have
space below it, whereas a y will have space above it.

Is this the cause of the problem you have?

Ollie

----- Original Message -----
From: "xico" <Click here to reveal e-mail address>
To: "ngfx-drawing" <Click here to reveal e-mail address>
Sent: Tuesday, November 27, 2001 7:58 PM
Subject: [ngfx-drawing] RE: MeasureString method

[Original message clipped]

Reply to this message...
 
 
System.Drawing.Font
System.Drawing.Graphics
System.Drawing.Pen
System.Drawing.SizeF
System.Drawing.SolidBrush




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification