2017-01-30 49 views
0

没有任何迹象表明一个简单的Windows窗体DragDrop在PowerShell中不起作用,并且有几个资源解释它可以正常工作,但是我无法让它们中的任何一个工作。即使是一些这样简单:PowerShell表单不会触发DragDrop

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事件触发正常不过。

回答

0

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

因为我在Windows 10上,我的PowerShell以管理员身份运行,所以我实际上可以做我需要的,但是用户级资源管理器进程(或其他以用户身份运行的任何对象)将只是拒绝与管理员级别的PowerShell表单进行交互。

作为一个用户运行PowerShell允许DragDrop按预期工作,但祝你好运,如果你需要它是管理员! > _>