首页 > 解决方案 > 处于关闭状态的 ComboBox 的鼠标事件处理程序

问题描述

这是我在其中寻找正确方法的代码,以在鼠标从列表中的一项移动到下一项时下拉处于按下状态时捕获任何鼠标移动。

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()

这可能吗?我已经尝试了所有可用的鼠标事件处理程序。

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

这是我希望发生的事件是当悬停在每个项目上时。

在此处输入图像描述

标签: powershell

解决方案


推荐阅读