Is it possible to vertically center text in controls and if it is, how?
I've tried searching this forum and the MSDN library with no results. :-(
Is it possible to vertically center text in controls and if it is, how?
I've tried searching this forum and the MSDN library with no results. :-(
Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.
I am, but it's only centering the text horizontally. It's still aligning the text to the top.
Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.
I don't know of a standard method to vertically center text but here is a method you could use:
1. Get the height of the text in the edit box.
2. Get the height of the edit box using GetClientRect.
3. Do the calculation to calculate the postion of centered text:
4. Use this value in a call to EM_SETRECT.Code:top = (client_height - font_height) / 2
Hm. That's a good idea, but it appears the EM_SETRECT only works for multiline edit controls.
I guess the easiest solution for the statics would then be to just do the drawing myself, using the text metrics approach you described. Thanks for the help!
Typing stuff in Code::Blocks 8.02, compiling stuff with MinGW 3.4.5.