Archived

This topic is now archived and is closed to further replies.

fredjordans

centering text

Recommended Posts

hey.. i was wondering how, if given a certain y coordinate on screen, you could center text along a given horizontal width. Say, for example, that this width is a 32pixel tile, and i want to center a label for it. How could I determine the starting x coordinate for drawing the text? Thanks!

Share this post


Link to post
Share on other sites
Hmm, I think I understand what you're asking. First you'll need to figure out where the center client coordinate is for the label you want to use.

Then use GetTextExtentExPoint() and it's siblings to figure out the width of the label. Divide by 2, subtract that number from the centered client coordinate from step one and draw there.

ms-help://MS.VSCC/MS.MSDNVS/gdi/fontext_9r77.htm

That's the list of the font functions.

[edited by - jonstelly on July 30, 2002 1:08:09 PM]

Share this post


Link to post
Share on other sites