Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Help with Forms/Picturebox/DragDrop

$
0
0

I'm trying to add drag and drop capabilities to a picturebox form object and need some help with events and methods. The idea is to drop a new jpg file from explorer to update the image in the picturebox. Thanks in advance.

-Andy

 

$jpgfile = Get-Item C:\Z\Pictures\test.jpg

[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")

[System.Windows.Forms.Application]::EnableVisualStyles()

$form = New-Object Windows.Forms.Form

$form.Text = "Drag and Drop Test"

$form.StartPosition="Manual"

$form.Location=New-Object System.Drawing.Point(0,0)

$form.Width = 300

$form.Height = 300

 

$picturebox = New-Object Windows.Forms.PictureBox

$picturebox.SizeMode="Zoom"

$picturebox.Width = 300

$picturebox.Height = 300

$picturebox.AllowDrop = $True

$picturebox.Add_DragOver({Write-Host "DragOver working"})

$picturebox.Add_DragEnter({Write-Host "DragEnter working"})

$picturebox.Add_DragLeave({Write-Host "DragLeave working"})

$picturebox.Add_DragDrop({Write-Host "DragDrop NOT working"})

$picturebox.Image = [System.Drawing.Image]::FromFile($jpgfile)

$form.Controls.Add($picturebox)

$form.ShowDialog() | Out-Null


Viewing all articles
Browse latest Browse all 6937

Trending Articles