在增加组合框高度超过默认高度后,如何使组合框数据在垂直方向上对齐? [英] How to make the combobox data to be aligned centred vertically after increasing the combobox height beyond the default height?
问题描述
最初我使用CCombobox :: SetItemHeight(-1,30)增加了组合框的高度,
直到这一点一切正常,但是一旦我增加了组合框的高度,组合框数据就不会集中对齐。它仍然在顶部对齐。
现在我想让组合框数据或文本对齐居中(垂直)。
任何人都可以让我知道如何将文本垂直居中对齐。
提前谢谢。
< blockquote>这不能以简单的方式实现。可以获得指向组合框的编辑或静态控件的指针。但是使用编辑控件无法设置垂直对齐,并且使用静态控件在创建控件后无法更改 SS_CENTERIMAGE
样式。
因此控件必须是子类(参见MSDN 如何将CListBox和CEdit子类化为内部CComboBox [ ^ ])。
对于静态控件,派生类必须在创建时设置 SS_CENTERIMAGE
样式。
对于编辑控件,您必须创建一个支持垂直居中显示的控件。搜索cedit vertical alignment将为您提供解决方案(例如 http://www.codeguru.com/cpp/vs/devstudio_macros/textoperations/article.php/c8491/Vertical-Text-Centering-in-an-Edit-Control.htm [ ^ ])。
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.
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 theSS_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 theSS_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[^]).
这篇关于在增加组合框高度超过默认高度后,如何使组合框数据在垂直方向上对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!