# Custom button in Message box

**URL:** <https://forums.powershell.org/t/custom-button-in-message-box/11331>\
**Category:** PowerShell Help\
**Created:** [September 19, 2018, 5:18am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331 "2018-09-19T05:18:19Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [September 19, 2018, 5:18am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/1 "2018-09-19T05:18:19Z")

</div>

```
[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 🙂

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [September 19, 2018, 8:51am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/2 "2018-09-19T08:51:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [September 19, 2018, 9:18am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/3 "2018-09-19T09:18:03Z")

</div>

Thanks Don, managed to get this from a MS demo and customise

&nbsp;

```
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"

}
```

&nbsp;

&nbsp;

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

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 19, 2018, 9:20am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/4 "2018-09-19T09:20:09Z")

</div>

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.
```

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [September 19, 2018, 9:38am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/5 "2018-09-19T09:38:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kvprasoon](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/kvprasoon/32/4449_2.png) [@kvprasoon](https://forums.powershell.org/u/kvprasoon)\
**Post date:** [September 19, 2018, 9:48am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/6 "2018-09-19T09:48:07Z")

</div>

I would echo Don’s reply.

---

<div class="post-metadata">

**Author:** ![postanote](https://avatars.discourse-cdn.com/v4/letter/p/ebca7d/32.png) [@postanote](https://forums.powershell.org/u/postanote)\
**Post date:** [September 19, 2018, 2:23pm UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/7 "2018-09-19T14:23:13Z")

</div>

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://www.donaldmellenbruch.com/post/introducing-the-anybox)

  
&nbsp;

> https://poshgui.com

&nbsp;

> Visual Studio Community Edition
> 
> > **[Visual Studio 2022 Community Edition – Download Latest Free Version](https://visualstudio.microsoft.com/vs/community/)**
> >
> > 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](https://foxdeploy.com/series/learning-gui-toolmaking-series)
> 
> &nbsp;

  
The above are freely available, or you can get this, but it’s not free:

> https://www.sapien.com/software/powershell\_studio

&nbsp;

---

<div class="post-metadata">

**Author:** ![mark-prior](https://avatars.discourse-cdn.com/v4/letter/m/c67d28/32.png) [@mark-prior](https://forums.powershell.org/u/mark-prior)\
**Post date:** [September 20, 2018, 2:14am UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/8 "2018-09-20T02:14:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:34pm UTC](https://forums.powershell.org/t/custom-button-in-message-box/11331/9 "2024-05-16T20:34:21Z")

</div>


