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

7 months ago.

  • Author
  • #112072

    Points: 42
    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



    not sure if there is a simple option or even a hard one as never really messed with windowsforms

    Help 🙂

  • #112099

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

  • #112123

    Points: 42
    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
    $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
    $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.Topmost = $true
    $result = $form.ShowDialog()
    if ($result -eq [System.Windows.Forms.DialogResult]::OK)
    Write-Host = "review"
    Write-Host = "Ignore"



    awaiting telling off for WH command :), just for demo purpose so its ok

  • #112124

    Points: 1,991
    Helping Hand
    Rank: Community Hero

    A different thought using ComObject.

    $r = New-Object -ComObject
    # 5 --> is the timeout for showing the popup
    # 6 --> CancelContinueTryAgain , Cancel and Continue can be used here.
  • #112127

    Points: 42
    Rank: Member

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

    • #112130

      Points: 1,991
      Helping Hand
      Rank: Community Hero

      I would echo Don's reply.

  • #112147

    Points: 1,347
    Helping Hand
    Rank: Community Hero

    FYI, if you start messing with PS with GUI. You don't have to do this from scratch.

    Use these resources:



    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:


  • #112166

    Points: 42
    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.

The topic ‘Custom button in Message box’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort