How can we vertically align text in edit box?(我们如何在编辑框中垂直对齐文本?)
问题描述
我创建了一个编辑框:
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.
这篇关于我们如何在编辑框中垂直对齐文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我们如何在编辑框中垂直对齐文本?


基础教程推荐
- 从 std::cin 读取密码 2021-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01