Magic Button Text Padding
-
How does Microsoft calculate the left alignment of text on a button? Test button settings: - All Margins set to 0. - All Padding set to 0. - TextAlign = MiddleLeft. - Button style is Flat. - Setting flat border width to 0 or 1 has no effect on position of text. For pattern illustration: - U = Unknown Pixel (we are not drawing these) - T = Text pixel My drawing: 1. Draw text at x = 0. 2. Draws text 5 pixels from left edge - I can live with that. Pattern: UUUUT Not important: Why is DrawString(...) drawing the text at x=4 instead of x=0? Microsoft drawing: 1. Draws text 11 pixels from left edge. Pattern: UUUUUUUUUUT Important: Where are the extra 6 pixels coming from? I have tried to account for the extra padding by examining the systems information settings. Unfortunately none of those settings explain where the padding is coming from (BorderSize=1, Border3DSize=2). Thanks for any explanation,
INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
-
How does Microsoft calculate the left alignment of text on a button? Test button settings: - All Margins set to 0. - All Padding set to 0. - TextAlign = MiddleLeft. - Button style is Flat. - Setting flat border width to 0 or 1 has no effect on position of text. For pattern illustration: - U = Unknown Pixel (we are not drawing these) - T = Text pixel My drawing: 1. Draw text at x = 0. 2. Draws text 5 pixels from left edge - I can live with that. Pattern: UUUUT Not important: Why is DrawString(...) drawing the text at x=4 instead of x=0? Microsoft drawing: 1. Draws text 11 pixels from left edge. Pattern: UUUUUUUUUUT Important: Where are the extra 6 pixels coming from? I have tried to account for the extra padding by examining the systems information settings. Unfortunately none of those settings explain where the padding is coming from (BorderSize=1, Border3DSize=2). Thanks for any explanation,
INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
One logical, if unlikely, hypothesis might be that the position of the first character is calculated based on the underlying bounding box of the character which may include a built-in left-margin factor. To exclude this hypothesis, which I'd guess you may have already done, I'd vary the first character from lower to upper case, and compare a "naturally wide" "W" with a "naturally narrow "I." If they are both drawn at identical distances from the left edge of the Button at the Alignment settings you describe: that's one less hypothesis :) A more probable hypothesis (?): the fact you are using the Paint Event and DrawString means you are relying on an internal drawing area that is offset from the absolute pixel edges of the Button: since I never use Paint and DrawString, I don't know how you could test this hypothesis, but I am sure someone else reading this post will. best, Bill
"It is the mark of an educated mind to be able to entertain a thought without accepting it." Aristotle