在增加组合框高度超过默认高度后,如何使组合框数据在垂直方向上对齐? [英] How to make the combobox data to be aligned centred vertically after increasing the combobox height beyond the default height?

查看:93
本文介绍了在增加组合框高度超过默认高度后,如何使组合框数据在垂直方向上对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





最初我使用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 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[^]).


这篇关于在增加组合框高度超过默认高度后,如何使组合框数据在垂直方向上对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆