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:
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With