我们如何在编辑框中垂直对齐文本? [英] How can we vertically align text in edit box?

查看:16
本文介绍了我们如何在编辑框中垂直对齐文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个编辑框:

m_EditWnd.Create(m_hWnd, rect, NULL, ES_LEFT | ES_AUTOHSCROLL | WS_CHILD |
                                     WS_OVERLAPPED | WS_VISIBLE,
                 WS_EX_CLIENTEDGE | WS_EX_LEFT | WS_EX_LTRREADING);

横向对齐的样式有ES_CENTER,文本横向对齐,但我们可以将文本垂直居中对齐吗?

There is a style for horizontal alignment as ES_CENTER for horizontal text alignment, but can we align text vertically centered?

推荐答案

我没有足够的声誉来发表评论,所以这里有一个非常古老的问题的可能有用的片段!

I don't have enough reputation to make a comment, so here's a possibly useful snippet to a very old question!

如果您提供 WS_BORDER 样式,则文本会根据要求自动垂直居中.由于 OP 使用的是 WS_EX_CLIENTEDGE,所以会绘制一个边框无论如何,因此添加这种样式应该不是问题.

If you supply the WS_BORDER style then the text gets automatically vertically centred, as requested. Since the OP is using WS_EX_CLIENTEDGE, a border is drawn anyway, so adding in this style shouldn't be a problem.

但是,WS_BORDER |WS_EX_CLIENTEDGE 仅实现部分"垂直居中.

However, WS_BORDER | WS_EX_CLIENTEDGE only achieves a "partial" vertical centring.

使用 WS_BORDER |WS_EX_STATICEDGE 实现了正确的垂直居中,尽管显然我们的视觉风格与客户端边缘风格略有不同.对我来说,我可以接受这个小小的权衡,而不是编写一个自定义编辑控件.

Using WS_BORDER | WS_EX_STATICEDGE achieves the proper, vertical centring, although obviously then we have a slightly different visual style to the client-edged style. For me, I could live with this minor trade-off, rather that write a custom edit control.

这篇关于我们如何在编辑框中垂直对齐文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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