PowerShell 窗体不会触发拖放



没有任何迹象表明一个简单的Windows Forms DragDrop在PowerShell中不起作用,并且有几个资源解释说它确实有效,但是我无法让它们中的任何一个工作。即使是这样简单的事情:

Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.Application]::EnableVisualStyles()
$form = New-Object System.Windows.Forms.Form
$TBcode = New-Object System.Windows.Forms.TextBox
$form.Controls.Add($TBcode)
$TBcode.Dock = "Fill"
$TBcode.Multiline = $true
$TBCode.ScrollBars = "Vertical"
$TBCode.AllowDrop = $true
$TBcode.Add_DragEnter({ Write-Host "DragEnter"; $_.Effects = "Copy" })
$TBcode.Add_DragDrop({ Write-Host "DragDrop" })
$TBcode.Add_MouseEnter({ Write-Host "Mouse Enter" })
$form.ShowDialog()

MouseEnter 事件正常触发,但是当尝试将任何内容拖入文本框时,没有任何反应。

我突然意识到,并能够确认这实际上是用户帐户控制。

因为我使用的是 Windows 10,所以我以管理员身份运行我的 PowerShell,

所以我实际上可以做我需要做的事情,但是用户级资源管理器进程中的对象(或以用户身份运行的任何其他内容)将简单地拒绝与管理员级 PowerShell 表单交互。

以用户身份运行PowerShell允许DragDrop按预期工作,但如果您需要它成为管理员,祝你好运!>_>

最新更新