Custom button in Message box

Welcome Forums General PowerShell Q&A Custom button in Message box

This topic contains 7 replies, has 4 voices, and was last updated by

 
Participant
1 month ago.

  • Author
    Posts
  • #112072

    Participant
    Points: 0
    Rank: Member
    [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 🙂

  • #112099

    Keymaster
    Points: 7
    Rank: Member

    Nope. You'd have to build a new form completely from scratch.

  • #112123

    Participant
    Points: 0
    Rank: Member

    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

  • #112124

    Participant
    Points: 65
    Published
    Rank: Member

    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.
    
  • #112127

    Participant
    Points: 0
    Rank: Member

    ^ nice, how would i customise the text in the buttons however ?

    • #112130

      Participant
      Points: 65
      Published
      Rank: Member

      I would echo Don's reply.

  • #112147

    Participant
    Points: 37
    PublishedHelping Hand
    Rank: Member

    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

    Free IDE and Developer Tools | Visual Studio Community

    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

     

  • #112166

    Participant
    Points: 0
    Rank: Member

    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.

You must be logged in to reply to this topic.