Graphical Text Size

  • Thread starter Thread starter Noah Coad [MVP]
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top