简体   繁体   English

Delphi:如何调整 TEdit 的文本垂直位置

[英]Delphi: How to adjust text vertical position of a TEdit

The text in a TEdit (or TCombo, TButtonedEdit) is always aligned to top. TEdit (或 TCombo、TButtonedEdit)中的文本始终与顶部对齐。 I have not found any property to change the alignment.我还没有找到任何属性来改变对齐方式。 Usually it is not a problem, unless I want to set a larger height.通常这不是问题,除非我想设置更大的高度。

I googled a little.我用谷歌搜索了一下。 There are solutions to adjust the left and the right margins by sending a Windows message.有一些解决方案可以通过发送 Windows 消息来调整左右边距。 But I have no idea, how to adjust the vertical alignment.但我不知道如何调整垂直对齐方式。

I do not want to use a larger font.我不想使用更大的字体。 Any ideas?有任何想法吗?

If there was such an option it would be applied by way of a style.如果有这样的选项,它将通过样式应用。 The EDIT control styles list contains no such style and so the conclusion is that the underlying control does not offer this functionality. EDIT控件样式列表不包含此类样式,因此结论是基础控件不提供此功能。

You'll have to either make a new control, or take over the painting yourself.您将不得不创建一个新控件,或者自己接管这幅画。 Neither is particularly appealing.两者都不是特别吸引人。

Dusting of an old question... I found a solution in a similar c++ question: https://stackoverflow.com/a/51079348/2107791一个老问题的除尘......我在一个类似的 c++ 问题中找到了一个解决方案: https : //stackoverflow.com/a/51079348/2107791

  • The text gets automatically vertically centred by setting TEdit's property BorderStyle to bsSingle .通过将 TEdit 的属性BorderStyle设置为bsSingle ,文本会自动垂直居中。
  • The trade-off is a border around the Edit box权衡是编辑框周围的边框

Works for me using Delphi 10.3 Rio.使用 Delphi 10.3 Rio 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM