Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a Listbox, how can I get the width of the listbox minus the space the scrollbar takes up?

I have a listbox that might contain strings that are wider than it. I'm too lazy to write resize code at the moment, so I'm displaying tooltips that show the entire item if it's too big to fit in the listbox.

Right now, I'm getting the width using the Width property, and comparing it to the result from MeasureText with the string and the font as arguments.

This works alright most of the time, but it doesn't work in the case where the item fits the listbox without a scrollbar but does not fit the somewhat slimmer listbox with the scrollbar.

So, how can I find out:

  1. if a listbox is displaying a scrollbar
  2. the width of the listbox not including the scrollbar

I guess 2 would be solved if the scrollbar takes up the same pixel width no matter what windows version or display configuration that version is running. Does anyone know if this is true or not?

like image 639
Isaac Bolinger Avatar asked Aug 04 '11 23:08

Isaac Bolinger


1 Answers

You can use the ListBox.ClientRectangle.Width to get the interior space used by the control.

If the ScrollBar is visible, the width value returned would be the interior width minus the ScrollBar width, so it's safe for you to measure against it.

like image 168
LarsTech Avatar answered Nov 06 '22 23:11

LarsTech