how to pad a label text by pixels ?

Recommended Posts

jennico 4

jennico 4

i want to pad a label text to the left and to the right with whitespaces, so the text does not start on the first label pixel, and in case of $SS_Right does not end on last pixel. there should be a constant gap to the label borders. (i don't mean center either)

if i choose spaces for the padding, the result will not be constant when a bigger font is used, but i need constant spacing no matter of the font.

the best would be to have the possibility to push the text x pixels to the right (and on $ss_right push it x pixel to the left).

Share this post

Link to post

Share on other sites

jennico 4

jennico 4

Windows XP: The calculated string width takes into account the intercharacter spacing set by the SetTextCharacterExtra function and the justification set by SetTextJustification. This is true for both displaying on a screen and for printing. However, if lpDx is set in ExtTextOut, GetTextExtentPoint32 does not take into account either intercharacter spacing or justification.

SetTextCharacterExtra will change the spacing between every word in the text string (this does not help either).

SetTextJustification works with chr(32) as well, not with pixels. so no help so far.

Share this post

Link to post

Share on other sites

jennico 4

jennico 4

well, okay, i really understand GetTextExtentPoint32 and i use it correctly. let's take the (modified) example by zedna.

the text in the label begins at label x point 0. what i want to achieve, is that the text begins not at 0, but - let's say - 25 pixel from the left side. constantly, no matter what font is used. when i pad it left with spaces, the result will not be constant, because the space character will grow with the font width.

i need some function that allows me to start the text exactly at x position 25 pixel from left side of the label.