如何在Delphi中设置TComboBox的列表框部分的制表符宽度
通过设置TListbox的TabWidth属性,可以轻松地在列表框中实现多列效果。例如,http://delphi.about.com/cs/adptips2000/a /bltip1200_3.htm
我需要在组合框的下拉列表中执行相同的操作,但组合框不发布任何 TabWidth 属性。
有什么想法吗?
You can easily achieve a multicolumn effect in a listbox by setting the TabWidth property of TListbox. For example, http://delphi.about.com/cs/adptips2000/a/bltip1200_3.htm
I need to do the same in the drop down list of a ComboBox, but comboboxes don't publish any TabWidth property.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在对 这个答案建议您自行绘制您所说的列表框项目:
组合框实际上由三个本机子窗口组成 - 组合框本身、嵌入式编辑和列表框。您可以使用
GetComboBoxInfo()
函数来填充
COMBOBOXINFO
结构(即TComboBoxInfo
记录),包含有关控件的信息,它将返回其中的 3 个HWND
元素。这样您就可以更改列表框的外观和行为。原则。对于要使用制表位的列表框,需要具有
LBS_USETABSTOPS
样式标志设置。不幸的是,此功能以后无法打开,必须使用它创建列表框。因此,仅当您能够打开列表框的样式标志(该列表框是在组合框的CreateWindowEx()
调用期间创建的)时,您才可以使用该功能。 AFAICS 这只能通过挂钩 CreateWindowEx() 调用本身、识别创建列表框的内部调用并更改传递的样式来完成。这意味着代码的运行时修改,不是在可执行文件中,而是在 Windows DLL 中。所有者绘制列表项看起来会容易得多。
In a comment to this answer advising you to owner-draw the list box items you say:
A combo box is actually composed of three native child windows - the combo box itself, an embedded edit, and a list box. You can use the
GetComboBoxInfo()
function to fill aCOMBOBOXINFO
structure (i.e. aTComboBoxInfo
record) with information about the control, and it will return the 3HWND
elements in it. With that you are able to alter the appearance and behaviour of the list box. In principle.For the list box to use the tab stops it needs to have the
LBS_USETABSTOPS
style flag set. Unfortunately this can't be turned on later, the list box has to be created with it. So you could use the functionality only if you were able to turn the style flag on for the list box, which is created during theCreateWindowEx()
call for the combo box. AFAICS this can only be done by hooking theCreateWindowEx()
call itself, identifying the internal call that creates the list box, and altering the passed style. This means runtime modification of code, and not in your executable but in a Windows DLL.Owner-drawing the list items looks like it would be much easier.
据我所知,这里没有像
TabWidth
那么简单的方法,但您可以重写Paint
方法并自己绘制它。查看列表框和组合框源可能会有所帮助。From what I know there is not so simple way as
TabWidth
here but you can overridePaint
method and draw it yourself. Looking at listbox and combobox sources may help.