1

I set the DrawMode 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?

3

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

1
  • I added an edit to explain what to set HorizintalExtent to. Basically the value of TextRenderer.MeasureText(text,listBox1.font).Width – Nick Aug 11 '11 at 13:08
0

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.