-
Notifications
You must be signed in to change notification settings - Fork 1
/
Show-GuiDatePicker.ps1
52 lines (43 loc) · 1.42 KB
/
Show-GuiDatePicker.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Show-GuiDatePicker {
<#
.SYNOPSIS
Display a Month Calendar in a pop up window
.DESCRIPTION
Displays a pop up window from which a non-technical user can choose a date during an automated routine
.PARAMETER Title
A title for the pop up window
#>
param (
# A title for the pop up window
[Parameter()]
[string]
$Title = 'Choose a Date'
)
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$global:chosendate = $null
$form = New-Object Windows.Forms.Form
$form.Size = New-Object Drawing.Size(233,190)
$form.StartPosition = "CenterScreen"
$form.KeyPreview = $true
$form.FormBorderStyle = "FixedSingle"
$form.Text = $title
$calendar = New-Object System.Windows.Forms.MonthCalendar
$calendar.ShowTodayCircle = $false
$calendar.MaxSelectionCount = 1
$form.Controls.Add($calendar)
$form.TopMost = $true
$form.add_KeyDown({
if($_.KeyCode -eq "Escape") {
$global:chosendate = $false
$form.Close()
}
})
$calendar.add_DateSelected({
$global:chosendate = $calendar.SelectionStart
$form.Close()
})
[void]$form.add_Shown($form.Activate())
[void]$form.ShowDialog()
Write-Output (Get-Date $global:chosendate)
}