Listbox - how to detect a Wheel Click?

Hello all,

I’d like to detect a mouse wheel click event, Can anyone tell me how to do this? The docs show a MouseWheel Event, but only for scrolling.

Alternatively, how to use the corner (top right) as a button that is clickable?

Thanks in advance!
Tim

[quote=227419:@Tim Seyfarth]Hello all,

I’d like to detect a mouse wheel click event, Can anyone tell me how to do this? The docs show a MouseWheel Event, but only for scrolling.
[/quote]
You can do anything you want in the event, but most would expect it to scroll so doing something else might be confusing to to your users.

First the top right corner will only be guaranteed to bot be a header if you have AutohideScrollbars = False And Vertical Scrollbar = true.

While It’s easy to detect a click there to cause an action, there is no way to give teh user a visual indication of a button from inside the listbox.

While I never tried it, you could try to put a button (or bevelButton) of the correct size over that area, and see how well that works visually.

  • Karen

Thanks Karen,
But do you know how to detect a wheel click event? That is what I am after - not a scroll…
Thanks,
Tim

[quote=227426:@Tim Seyfarth]Thanks Karen,
But do you know how to detect a wheel click event? That is what I am after - not a scroll…
Thanks,
Tim[/quote]

In the MouseWheel event. As i said you can do whatever you want in the event… If you return true from the event, the listbox will not scroll

  • Karen

According to the Docs and my test, that event only fires on mouse move, not mouse click.

I’m not sure that without declares you can detect the mouse wheel being clicked

I’d have to dig out an old wired mouse with a wheel to see if the click of the wheel is reported at all

Ah! I was thinking you wanted to do something when they moved the scroll wheel- but just not scroll the listbox. (I use a magic mouse so I don’t think of a click with a scrolling)

I think Norm is right that you would need declares…

If this is Xplatform you might want to use your button idea…

Maybe see how overlaying a button in teh upper right corner works…Or Use a Container control with an external scrollbar and a button

One other approach… Use a modifier key with a left or right click to do whatever action you want… in the Click event check for whatever other key being down you want.

  • karen

For Mac see https://forum.xojo.com/18485-mouse-wheel-press-event/0

For Windows it is probably detectable with mouse_event. See
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646260(v=vs.85).aspx?f=255&MSPPError=-2147217396

[quote=227419:@Tim Seyfarth]Alternatively, how to use the corner (top right) as a button that is clickable?
[/quote]

From inside your app, System.MouseX and System.MouseY together with System.MouseDown let you see where the mouse has been clicked all over the screen. Use a timer with a period or 20 or so to monitor these values, and when MouseDown occurs within 20, Screen(0).Width-20 for instance you do what you need.

The app window will lose focus when you click out of it, though. You will need to use a declare to bring it back. I guess since you talk about wheel we are in the Windows world, so WFS contains the SetWindowPos call that can do that.

Still about Windows, the choice of right corner may not be the best in Windows 8, where it could display the Charm bar. It is alright in Windows 10 and 7, though.

After a quick experiment it appears the win32 mouse_event function does not detect Mouse Wheel press.

Why not go for middle button, which is obtained by pressing both buttons ?

Is there a way to detect in the column header, which is also a sorted column, which mouse button has been clicked and either do the sort, or do something else?

Thanks
Tim

I got something to work - not with a specific left or right mouse click, but only if the mouse in the top right corner. Here’s the code:

Mouse Down Event

  Dim Row As Integer = Me.RowFromXY(x,y)
  Dim Col As Integer = Me.ColumnFromXY(x, y)
  
  //Make sure we are in the top right corner of listbox with a vertical ScrollBar
  If (x > (Me.Width - 19)) And Row = -1 and Col = -1 Then 
    Return True
  Else
    Return False
  End If

Mouse Up Event

  Dim row As Integer = Me.RowFromXY(x, y)
  Dim col As Integer = Me.ColumnFromXY(x, y)
  Dim Chk As Boolean = False
  Dim H As Integer  = Me.HeaderHeight - y
  
  If x > (Me.Width - 19) Then
    // If Me.ScrollBarVertical = True Then 
    
    If Row = -1 and Col = -1 And H > 0 Then 
      Chk = Me.CellCheck( 0, 0 )
      If Chk = False Then 
        Chk = True
      Else
        Chk = False
      End If
      
      For i As Integer = 0 to Me.ListCount - 1
        Me.CellCheck( i, 0 ) = Chk
      Next i
    End If
  End If   

If the mouse is in the top right, it will check all of the rows in column 0. If it is not in the top right corner, the header will sort (in this case).

Tim