Click here to Skip to main content
15,895,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Initially I increased the height of the combobox using CCombobox::SetItemHeight(-1,30),

Till this point everything is ok,But as soon as I increased the height of the combobox,the combobox data is not centrally aligned.Still it is being aligned at the top.

Now I want to make the combobox data or text to be aligned centred (Vertically).

Can anyone please let me know how can I align the text vertically centred.

Thanks in advance.
Posted

1 solution

This can't be achieved in a simple way. It is possible to get a pointer to the edit or static control of the combo box. But with edit controls the vertical alignment can't be set and with static controls the SS_CENTERIMAGE style can't be changed after the control has been created.

So the control must be subclassed (see MSDN How to subclass CListBox and CEdit inside of CComboBox [^]).

For a static control, the derived class must set the SS_CENTERIMAGE style upon creation.

For an edit control you must create one that supports vertically centered display. Searching for "cedit vertical alignment" will give you solutions (e.g. http://www.codeguru.com/cpp/v-s/devstudio_macros/textoperations/article.php/c8491/Vertical-Text-Centering-in-an-Edit-Control.htm[^]).
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900