1

I have used some code in VB.net which detects when a mouse button is clicked (rather conveniently works with right click, left click and middle click not sure about the forward and back buttons, since my mouse doesn't have those), and it outputs what was clicked and which button was used. However, it only seems to detect a left click when clicking on an object (a list box I called lstDebug, which outputs the thing I clicked on and which button was used).

Public Sub ClickHandler(sender As Object, e As MouseEventArgs) Handles Me.MouseClick, lstDebug.MouseClick

    lstDebug.Items.Add(sender.name)
    lstDebug.Items.Add(e.Button.ToString)

It outputs fine (outputted text goes as follows:)

Form1
Right
lstDebug
Left

But gives no indication of a right click or middle click when the cursor is on the list box.

Is this a bug, something which is meant to be there for a reason and there's no way around it, or is there a code solution? Thanks. This is what the form/design looks like, the list box is in blue

Joss
  • 67
  • 6
  • By the way, here is where I got the original code from: https://stackoverflow.com/questions/37638463/how-do-i-detect-a-mouse-click-anywhere-on-a-form-in-vb-net – Joss May 07 '18 at 15:08
  • 1
    Seems to be a bug: https://stackoverflow.com/questions/9220501/right-click-to-select-items-in-a-listbox – MatSnow May 07 '18 at 15:12
  • 2
    Use the `MouseDown` or `MouseUp` event. For some reason, right-click and middle-click don't work with ListBox when using the `MouseClick` event. – 41686d6564 stands w. Palestine May 07 '18 at 15:18

0 Answers0