开发者

how to set the tabwidth of the listbox portion of a TComboBox in Delphi

开发者 https://www.devze.com 2022-12-20 12:39 出处:网络
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

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.

开发者_Python百科

Any ideas?


In a comment to this answer advising you to owner-draw the list box items you say:

I'm wondering why I must do that when the required functionality already exists on a listbox

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 a COMBOBOXINFO structure (i.e. a TComboBoxInfo record) with information about the control, and it will return the 3 HWND 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 the CreateWindowEx() call for the combo box. AFAICS this can only be done by hooking the CreateWindowEx() 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.


From what I know there is not so simple way as TabWidth here but you can override Paint method and draw it yourself. Looking at listbox and combobox sources may help.

0

精彩评论

暂无评论...
验证码 换一张
取 消