开发者

Setting DrawMode in ListBox removes horizontal scroll bar

开发者 https://www.devze.com 2023-03-10 17:13 出处:网络
I set the Dra开发者_如何学CwMode in my listbox control to OwnerDrawFixed so that I can color some items. When an item is too long to fit in the horizontal space of the list box no horizontal scoll app

I set the Dra开发者_如何学CwMode in my listbox control to OwnerDrawFixed so that I can color some items. When an item is too long to fit in the horizontal space of the list box no horizontal scoll appears.

How can I make the scrollbar appear?


you should set HorizontalExtent property of listbox in OwnerDrawFixed mode

    listBox1.HorizontalExtent = xx; //xx can be maximum size list box item fills

To determine the value that HorizontalExtent should be set to use the following method on the the strings in your list box and get the Width property:

TextRenderer.MeasureText(text, listBox1.font)

Set HorizontalExtent to the largest Width value that MeasureText returns


You'll have to use ListBox.MeasureItem event. See the example in msdn page.

0

精彩评论

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