Detect click on Listbox's scrollbar

Hello,
is there a way to detect a click event on listbox’s scrollbar?

In other words I want know when a user click or drag the scrollbar

thanks

Use the MouseDown event of the listbox. It fires when the scrollbar is clicked. Use X to see if the click is within the scrollbar (> Me.width-16)

MouseDown event not work on windows

Only problem is that fires even if there is no scrollbar.

That assumes you know the scrollbar is visible. If AutohideScrollbar is false AND VerticalScrollBar is true then you know you have one and can use that code.

If AutohideScrollBar = True and VerticalScrollBar = True, assuming no horizontal scroll, If the listbox has at least one row, Use RowFromXY on the first displayed row to check the X value if it is in the potential scrollbar area. In that case if it returns -1 then the click was on the scroll bar.

If there is a HorizontalScrollBar it’s a little more complicated because you then also have to worry about the Y.
.

What do you mean “not work” ? How ? You must have added the MouseDown event somewhere else (in the window ?). If you add the event to the listbox, it works ! Just put “beep” in there, and you will see…

[quote=87834:@Karen Atkocius]That assumes you know the scrollbar is visible. If AutohideScrollbar is false AND VerticalScrollBar is true then you know you have one and can use that code.
[/quote]

You are right, of course.

From what I can see, RowFromXY reports -1 whenever I click in the scrollbar, no matter the horizontal scroll position. Same thing for the horizontal scroll bar, indifferent from the vertical scroll position.

This is a nice way of testing if the click is in the scrollbar, that detects at the same time if the scrollbar is there. Thank you Karen.

True but -1 does not mean the click IS in a scrollbar. RowFromXY will report -1 for a header click.
If you need to know if the click is in teh vertical or horizontal scrollbar,
There is the special case where there are both a vertical and horizontal scrollbar visible.

If the user clicks in the lower righthand corner RowFromXY will return -1 but they will not have clicked on either scrollbar.

[quote=87883:@Karen Atkocius]True but -1 does not mean the click IS in a scrollbar. RowFromXY will report -1 for a header click.
If you need to know if the click is in teh vertical or horizontal scrollbar,
There is the special case where there are both a vertical and horizontal scrollbar visible.[/quote]

I did not know RowFromXY and thought that was the solution. After all, you are the best Listbox specialist I know of.

So my original approach stands a better chance, on the condition to check if ScrollBarVertical or ScrollBarHorizontal is True. And that Y or X is not within the scrollbar arrows on PC and Linux.