PowerShell拖动;丢失失败

时间:2011-07-08 12:27:29

标签: powershell drag-and-drop

与Drag&amp ;;有问题在下面的ps1脚本中删除文件。它不起作用(“事件丢弃”不输出)与PowerGui,PowerShell ISE,也不作为

$installDir = Split-Path -Path $myinvocation.mycommand.path
& $env:SystemRoot\system32\WindowsPowerShell\v1.0\powershell.exe -sta (Join-Path $installDir "TestDrop.ps1") 

任何帮助将不胜感激。

## TestDrop.ps1 for testing drag & drop

function DragNDrop {
#region Import the Assemblies
[reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") | Out-Null
[reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
[reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") | Out-Null
[reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") | Out-Null

#endregion

[System.Windows.Forms.Application]::EnableVisualStyles()
$objForm = New-Object System.Windows.Forms.Form 
$objTextBox = New-Object System.Windows.Forms.TextBox 

$handler_DragEnter={    
    write-host "$Event Enter" 
    $Event.Effect = "Copy" # not sure about this ...
}

$objForm.Text = "Test Drag & Drop"
$objForm.Size = New-Object System.Drawing.Size(200,200) 
$objForm.StartPosition = "CenterScreen"
$objForm.KeyPreview = $True
$objForm.SizeGripStyle = 'Hide'
$objForm.FormBorderStyle = 'Fixed3D'

$objTextBox.AllowDrop = $true
$objTextBox.Location = New-Object System.Drawing.Size(10,25) 
$objTextBox.Size = New-Object System.Drawing.Size(120,120)  
$objTextBox.Multiline = $true
$objTextBox.TabIndex = 1
$objTextBox.Text = "Try to Drag & Drop File Here..."
$objTextBox.Add_DragEnter({ write-host "Event Enter" })
$objTextBox.Add_DragDrop({ write-host "Event Drop" })
$objForm.Controls.Add($objTextBox)
$objForm.Topmost = $True

return $objForm.ShowDialog()

} #End Function

DragNDrop | Out-Null 

1 个答案:

答案 0 :(得分:1)

你应该像这样启用droppiong

$objTextBox.Add_DragEnter({ 
  write-host "Event Enter" 
  $_.Effect = 'Copy'
})