Graphical Text Size

N

Noah Coad [MVP]

How does one obtain the physical dimensions (in pixels) of some text (with a
specific font)?



I need to write text to a 'Graphics' object that must be centered, and in
order to center the text I need to know what it's size will be.



Your help is much appreciated!


Noah Coad
-=[ Know-a-Code ]=-

Microsoft MVP & MCP (.NET/C#) | coad.net/noah
 
N

Noah Coad [MVP]

Perfect! Thanks!


Philip Rieck said:
Graphics.MeasureString() is what you're probably looking for.


Noah Coad said:
How does one obtain the physical dimensions (in pixels) of some text
(with
a
specific font)?



I need to write text to a 'Graphics' object that must be centered, and in
order to center the text I need to know what it's size will be.



Your help is much appreciated!


Noah Coad
-=[ Know-a-Code ]=-

Microsoft MVP & MCP (.NET/C#) | coad.net/noah
 
R

Ron Allen

Noah,
Make sure you look at the overloads for this as the default includes
some padding around the string boundary. StringFormat.GenericTypographic
will give better measurement results. Construct your own StringFormat if
you need to handle other things such as trailing spaces.

Ron Allen
Noah Coad said:
Perfect! Thanks!


Philip Rieck said:
Graphics.MeasureString() is what you're probably looking for.


Noah Coad said:
How does one obtain the physical dimensions (in pixels) of some text
(with
a
specific font)?



I need to write text to a 'Graphics' object that must be centered, and in
order to center the text I need to know what it's size will be.



Your help is much appreciated!


Noah Coad
-=[ Know-a-Code ]=-

Microsoft MVP & MCP (.NET/C#) | coad.net/noah
 
N

Noah Coad [MVP]

That is particularly interesting. Thanks Ron...


Ron Allen said:
Noah,
Make sure you look at the overloads for this as the default includes
some padding around the string boundary. StringFormat.GenericTypographic
will give better measurement results. Construct your own StringFormat if
you need to handle other things such as trailing spaces.

Ron Allen
Noah Coad said:
Perfect! Thanks!


Philip Rieck said:
Graphics.MeasureString() is what you're probably looking for.


How does one obtain the physical dimensions (in pixels) of some text (with
a
specific font)?



I need to write text to a 'Graphics' object that must be centered,
and
in
order to center the text I need to know what it's size will be.



Your help is much appreciated!


Noah Coad
-=[ Know-a-Code ]=-

Microsoft MVP & MCP (.NET/C#) | coad.net/noah
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top