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.
This topic is 3 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
TheVito
Posts: 12
Last visit: Fri Nov 25, 2022 7:59 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: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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
}
This topic is 3 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked