How can a add an icon on the titlebar and before the label text (hand or warning icon)
Text = “Copy started please wait until the next popup!”
===================
See example below.
===================
function New-PopUpForm {
Add-Type -AssemblyName System.Windows.Forms
Create the form.
$objForm = New-Object System.Windows.Forms.Form -Property @{
Text = “Copy Files V2.0”
BackColor = ‘white’
Size = New-Object System.Drawing.Size 300, 100
StartPosition = ‘CenterScreen’ # Center on screen.
FormBorderStyle = ‘FixedSingle’ # fixed-size form
# Remove interaction elements (close button, system menu).
ControlBox = $false
}
Create a label…
$objLabel = New-Object System.Windows.Forms.Label -Property @{
Location = New-Object System.Drawing.Size 30, 20
Size = New-Object System.Drawing.Size 250, 20
Text = “Copy started please wait until the next popup!”
}
… and add it to the form.
$objForm.Controls.Add($objLabel)
Override the .Show() method to include
a [System.Windows.Forms.Application]::DoEvents(), so as
to ensure that the form is properly drawn.
$objForm | Add-Member -Force -Name Show -MemberType ScriptMethod -Value {
$this.psbase.Show() # Call the original .Show() method.
# Activate the form (focus it).
$this.Activate()
[System.Windows.Forms.Application]::DoEvents() # Ensure proper drawing.
}
Since this form is meant to be called with .Show() but without
a [System.Windows.Forms.Application]::DoEvents() loop, it
it is best to simply hide the cursor (mouse pointer), so as not
to falsely suggest that interaction with the form is possible
and so as not to end up with a stuck “wait” cursor (mouse pointer) on
the first instantiation in a session.
Return the form.
return $objForm
}
$form = New-PopupForm
$form.Show()