2011-07-08 88 views
-1

遇到拖拽問題&在下面的ps1腳本中拖拽文件。它不工作(「事件Drop」不輸出)與PowerGUI的,PowerShell ISE中,也不是PowerShell拖放失敗

$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 
+0

「它不工作」 - 在什麼時尚? – EBGreen

+0

write-host命令不執行/輸出 – Les

+0

這是腳本的整個主體?它看起來很多都不見了。 – JNK

回答

1

您應該啓用droppiong這樣

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

的結尾明白了/ spasibo!/ if($ _.Data.GetDataPresent([Windows.Forms.DataFormats] :: FileDrop,$ false)) {__效果= 「複製」 } – Les