[System.Windows.Forms.MessageBox]::Show('Review Outstanding Timesheet', 'Urgent', 'Yesno')
Not to sure this is strictly a PS question, the above is working fine but i would like to customise the buttons to read
Complete
Ignore
not sure if there is a simple option or even a hard one as never really messed with windowsforms
Help
donj
September 19, 2018, 8:51am
2
Nope. You’d have to build a new form completely from scratch.
Thanks Don, managed to get this from a MS demo and customise
Â
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = 'Timesheet reminder'
$form.Size = New-Object System.Drawing.Size(300,200)
$form.StartPosition = 'CenterScreen'
$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Point(75,120)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = 'Review'
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Point(150,120)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = 'Ignore'
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $CancelButton
$form.Controls.Add($CancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,50)
$label.Text = "'Please would you complete your timesheet(s) to enable the timely recognition of costs on our projects and the billing of these to clients, if applicable.
"
$form.Controls.Add($label)
$form.Topmost = $true
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
Write-Host = "review"
}
Else
{
Write-Host = "Ignore"
}
Â
Â
awaiting telling off for WH command :), just for demo purpose so its ok
A different thought using ComObject.
$r = New-Object -ComObject wscript.shell
$r.Popup('Title',5,'Message',6)
# 5 --> is the timeout for showing the popup
# 6 --> CancelContinueTryAgain , Cancel and Continue can be used here.
^ nice, how would i customise the text in the buttons however ?
I would echo Don’s reply.
FYI, if you start messing with PS with GUI. You don’t have to do this from scratch.
Use these resources:
https://www.powershellgallery.com/packages/AnyBox/0.3.0
https://www.donaldmellenbruch.com/post/introducing-the-anybox
https://poshgui.com
Visual Studio Community Edition
Try our free, fully-featured, and extensible IDE for creating modern developer apps for Windows, Android, & iOS. Download Community for free today!
https://foxdeploy.com/series/learning-gui-toolmaking-series
The above are freely available, or you can get this, but it’s not free:
https://www.sapien.com/software/powershell_studio
Thanks all, ive created quite a few apps with Sapien, its a great tool and take sthe hard work of creating the forms out of the equation, great for speed but bad for learning
this needed to be ran as a scheduled task and pop the box up on screen.