Mouse Event Handler for ComboBox in its downed state

Viewed 139

Here's the code that I have where I was looking for the correct method to capture any mouse movements when the dropdown is in its downed state when the mouse is moved from one item in the list to the next.

Add-Type -AssemblyName System.Windows.Forms

$Form                        = New-Object System.Windows.Forms.Form
$Form.StartPosition          = 'CenterScreen'

$cbSearch                    = New-Object System.Windows.Forms.ComboBox
$cbSearch.Width              = 280
$cbSearch.Items.AddRange(@('Mixed content', 'More stuff', 'ANOTHER THING CONTENT', 'Item ?', 'Mixed item'))
$Form.Controls.Add($cbSearch)

# Event handler required for when the dropdown is in it's downed state. Like
# MouseCaptureChanged only when the dropdown is down and the mouse is moved over
# each item.
$cbSearch.Add_MouseCaptureChanged({ selectChanged $this $_ })

# Event handler action for the cbSearch control.
function selectChanged ($sender, $event) {
  write-host ($cbSearch.Text)
}

[void]$Form.ShowDialog()

Is this possible I've tried all the mouse event handlers available that I could see.

$cbSearch.Add_MouseCaptureChanged({ selectChanged $this $_ })
$cbSearch.Add_MouseEnter({ selectChanged $this $_ })
$cbSearch.Add_MouseHover({ selectChanged $this $_ })
$cbSearch.Add_MouseLeave({ selectChanged $this $_ })

This is when I would like the even to occur is when hovering over each item.

enter image description here

0 Answers
Related