ScrollBar Width

Is there a way to detect the width of a Window, Panel or ListBox scrollbar?

Widths are MacOS < Windows7 < Windows10

I have a listbox with auto-hide vertical scrollbar, and I’d like to know what it’s width WILL be, cross-platform. I’m not manually setting the width, I’m just using the default Scrollbar.

I tried programmatically adding a Scrollbar to see if I could read it’s Width property, e.g.

SB = New ScrollBar
But SB.Width = 0, So I assume there’s no “default” width.

For windows, this will return the system width of the scrollbar.

Const SM_CXVSCROLL = 2 Declare Function GetSystemMetrics Lib "User32.dll" Alias "GetSystemMetrics" (nIndex As Int32) As Int32 Dim scrollbarVerticalWidth As Integer = GetSystemMetrics(SM_CXVSCROLL)

Unfortunately ListBox doesn’t respond to SBM_GETSCROLLBARINFO messages (either due to a bug or its just not been implemented) so you can’t use GetScrollBarInfo to get the live information about the scrollbar from the control.

Maybe someone can chip in with the mac info?

I have always used 15 for mac without any issues (or at least none that jumped at me :slight_smile: )

Thanks, Julian.
AFAICT, the Scrollbar width in MacOS seems consistent, at least on Mojave and Catalina, so likely less of an issue there.
I expect that with the customizability of the Windows UI by the user, Scrollbars can be all over the place, so your function may be all I need.
Damn I miss VS!

Just a thought, but if a Xojo control has a scrollbar, I assume the control is using the same ScrollBar as the one we can drag in from the IDE Library (at least I think the ListBox is using that).

If that is the case, maybe a simple solution is to have a ScrollBar hidden (Visible=False) on your Window somewhere (not wired up to anything), and just check the width from that?

I know Windows permits a user-defined width, so the value could be almost anything. So if the width is changed, presumably your hidden ScrollBar will update too.

Maybe my suggestion is not elegant, but it should work. I hope that helps.