How to capture a rightclick event in a listbox

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
TheVito
Posts: 12
Joined: Mon Sep 25, 2017 4:27 am

How to capture a rightclick event in a listbox

Post by TheVito »

I want to capture a rightclick event on a listbox and send the text to set-clipboard.
I can't figure out how to test the event if it was a right click, I added the even mouse down, not sure how to
see what is available in the $_ = [System.Windows.Forms.MouseEventArgs] to test if the right mouse button was clicked.

jvierra
Posts: 14674
Joined: Tue May 22, 2007 9:57 am
Answers: 6
Has voted: 1 time
Been upvoted: 5 times
Contact:

Re: How to capture a rightclick event in a listbox

Post by jvierra »

Just check the button to see which one was clicked:

Code: Select all

$listbox1_MouseClick=[System.Windows.Forms.MouseEventHandler]{
#Event Argument: $_ = [System.Windows.Forms.MouseEventArgs]
	Write-Host $_.Button
}

Locked