Setting DrawMode in ListBox removes horizontal scroll bar
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.
精彩评论