在组合框中对齐文本 [英] Align Text in Combobox

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

问题描述

我想在组合框中对齐我的文本,以便它显示在组合框的中心告诉我如何执行此操作,您还可以看到组合框周围有一个默认边框,当它处于焦点时我如何删除那个边界也请解决我的两个问题谢谢

I want to align my text in combo box so that it will show in the center of combobox tell me how to do this also you can see there is a default border around a combo box when it is in focus how can i remove that border also Kindly solve my two problems Thanks

推荐答案

ComboBox 不支持此功能.确切的原因在时间的迷雾中迷失了,ComboBox 自 90 年代初就已经存在,但肯定与让文本框部分中的文本与下拉文本中的文本对齐的尴尬有关.用DrawItem自定义绘图也解决不了,只会影响下拉项的外观.

This isn't supported for ComboBox. The exact reasons are lost in the fog of time, ComboBox has been around since the early nineties, but surely has something to do with the awkwardness of getting the text in the textbox portion to line up with the text in the dropdown. Custom drawing with DrawItem cannot solve it either, that only affects the appearance of the dropdown items.

作为一种可能的解决方法,您也许可以做一些奇怪的事情,例如用空格填充项目字符串,使它们看起来居中.您需要使用 TextRenderer.MeasureText() 来确定要为每个项目添加多少个空格.

As a possible workaround, you could perhaps do something outlandish like padding the item strings with spaces so they look centered. You'll need TextRenderer.MeasureText() to figure out how many spaces to add for each item.

您所说的边框"不是边框,而是焦点矩形.您也无法摆脱它,Windows 拒绝让您创建一个不会显示带有焦点的控件的 UI.喜欢键盘而不是鼠标的用户关心这一点.没有解决方法.

The "border" you are talking about is not a border, it is the focus rectangle. You can't get rid of that either, Windows refuses to let you create a UI that won't show the control with the focus. Users that prefer the keyboard over the mouse care about that. No workaround for that one.

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

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