Click to See Complete Forum and Search --> : Getting Text point size.


GremlinSA
October 29th, 2008, 05:05 AM
In VB6 you could use a label or textbox to find the point size of any text..

Unfortunately i cant seem to find the same for VB.NET (2008) ..

Any one got any ideas on where i can find it...

Thanks

Gremmy..

HanneSThEGreaT
October 29th, 2008, 05:22 AM
Hey bud! Long time no see / hear! :(

You could use the built in MeasureString method from your Graphics object.
So, you create a Graphics object, then use MeasureString ( with the appropriate Font Size ). Once that is done, you could make a SizeF object, set it equal to the result of the MeasureString method; then, you could get access to the SizeF object's Height & Width objects.

Have a look at this :
http://www.thescarms.com/dotnet/MeasureString.aspx

http://www.codeproject.com/KB/GDI-plus/MeasureStrings.aspx

http://www.java2s.com/Tutorial/VB/0300__2D-Graphics/GraphicsMeasureString.htm

Hope that helps! :wave:

GremlinSA
October 29th, 2008, 06:40 AM
Ahhh .. thanks boet.

I didn't think of looking in the graphics object ..

I'm formatting text to print receipts and need to center and right justify the text, and for those calcs you need the text point size.

Wow .. the receipt looks tons better with the right formatting ...

Thanks...

HanneSThEGreaT
October 29th, 2008, 07:54 AM
Glad you came right boet! :thumb:

Yeah, I agree about the Graphics object. To me it does make sense having the MeasureString in there, but, on the other hand, it causes more work that what it should have, if there was an equivalent in the String class(es). That would be handy one day LOL!