I am tring to make a form with several images that will open a URL. Is it possible to add the click event to the function itself or do I have to add it after the function has been called?
Add-Type -AssemblyName System.Windows.Forms, System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()
$Form = New-Object system.Windows.Forms.Form
$Form.StartPosition = "CenterScreen"
$Form.Size = New-Object System.Drawing.Point(800,800)
$Form.text = "Example Form"
$Form.TopMost = $false
$Form.MaximumSize = $Form.Size
$Form.MinimumSize = $Form.Size
$Form.BackColor = "#000000"
function pictureBox {
[CmdletBinding()]
param (
[Parameter (Mandatory = $True)]
[string] $p,
[Parameter (Mandatory = $True)]
[int] $lx,
[Parameter (Mandatory = $True)]
[int] $ly,
[Parameter (Mandatory = $True)]
[string] $url
)
$img = [Drawing.Image]::Fromfile($PSCmdlet.GetUnresolvedProviderPathFromPSPath($p))
[Windows.Forms.PictureBox]@{
Size = [Drawing.Size]::new($img.Size.Width, $img.Size.Height)
Location = [Drawing.Point]::new($lx, $ly)
Image = $img
}
Add_Click ( { start-process $url } )
}
$v1 = pictureBox -p "C:\Users\User\Desktop\t.png" -lx 20 -ly 65 -url **THE-URL**
$v1.Add_Click( { start-process **THE-URL** } )