PowerShell 表单不会触发 DragDrop
PowerShell Forms Won't Trigger DragDrop
没有任何迹象表明简单的 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 事件正常触发,但是当尝试将任何内容拖入 TextBox 时没有任何反应。
我恍然大悟,确认这确实是用户帐户控制。
因为我在 Windows 10 我有我的 PowerShell 运行 作为管理员,所以我实际上可以做我需要做的,但是来自 User-level Explorer 的对象进程(或任何其他 运行 作为用户)将简单地拒绝与 Administrator-level PowerShell 表单交互。
运行 PowerShell 作为用户允许 DragDrop 按预期工作,但如果您需要它作为管理员,祝您好运! >_>
没有任何迹象表明简单的 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 事件正常触发,但是当尝试将任何内容拖入 TextBox 时没有任何反应。
我恍然大悟,确认这确实是用户帐户控制。
因为我在 Windows 10 我有我的 PowerShell 运行 作为管理员,所以我实际上可以做我需要做的,但是来自 User-level Explorer 的对象进程(或任何其他 运行 作为用户)将简单地拒绝与 Administrator-level PowerShell 表单交互。
运行 PowerShell 作为用户允许 DragDrop 按预期工作,但如果您需要它作为管理员,祝您好运! >_>