-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
「它不工作」 - 在什麼時尚? – EBGreen
write-host命令不執行/輸出 – Les
這是腳本的整個主體?它看起來很多都不見了。 – JNK