Created
March 22, 2012 17:48
-
-
Save ser1zw/2160887 to your computer and use it in GitHub Desktop.
PowerShell Drag & Drop sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PowerShell Drag & Drop sample | |
# Usage: | |
# powershell -sta -file dragdrop.ps1 | |
# (-sta flag is required) | |
# | |
Function DragDropSample() { | |
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | |
$form = New-Object Windows.Forms.Form | |
$form.text = "Drag&Drop sample" | |
$listBox = New-Object Windows.Forms.ListBox | |
$listBox.Dock = [System.Windows.Forms.DockStyle]::Fill | |
$handler = { | |
if ($_.Data.GetDataPresent([Windows.Forms.DataFormats]::FileDrop)) { | |
foreach ($filename in $_.Data.GetData([Windows.Forms.DataFormats]::FileDrop)) { | |
$listBox.Items.Add($filename) | |
} | |
} | |
} | |
$form.AllowDrop = $true | |
$form.Add_DragEnter($handler) | |
$form.Controls.Add($listBox) | |
$form.ShowDialog() | |
} | |
DragDropSample | Out-Null |
When I try to run this script in VS Code, the console just spins and spins. Does this script depend on something else?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome!