-
DrawText - DT_CALCRECT
I'm using DrawText to output some text (duh!) to a PictureBox. But first, I call it using DT_CALCRECT so I can know the dimension of the text so I can center it, but this does not work very well, because for example, DrawText returns 13 as the height, but if I manually measure the height of the text in MSPaint, the height is 11.
BTW, I must center the text manually, i.e., without using centering parameters in DrawText.
Thanks in advance.
-
I found the cause...
It appears Windows adds those extra pixels as the size letters like p, q, have below the "margin" line. So, now I'd need to know what that extra size is for a given font... Is this possible?
-
You can use GetTextMetrics() on the DC to get that value. The TEXTMETRIC struct will be filled with the info of the DC's font, and the particular thing you're asking about, the height below the line, is given by the tmDescent member. tmAscent is the height above the line, and tmHeight is the sum of those two.
-
That's what I was looking for! Thanks a lot.