Skip to content

Instantly share code, notes, and snippets.

@pierre3
Created December 11, 2014 13:24
Show Gist options
  • Save pierre3/8dc603b92068e9875bf8 to your computer and use it in GitHub Desktop.
Save pierre3/8dc603b92068e9875bf8 to your computer and use it in GitHub Desktop.
function Get-DatePicker
{
[CmdletBinding()]
[OutputType([System.DateTime])]
Param([string]$windowTitle=$null)
Add-type -AssemblyName "System.windows.forms"
$winForm = New-object Windows.Forms.Form
if([string]::IsNullOrEmpty($windowTitle)){
$winForm.Text = "DatePicker Control"
}else{
$winForm.Text = $windowTitle
}
$winForm.Size = New-Object Drawing.Size(200,55)
$winForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$winform.Add_Shown({ $winForm.TopMost = $true; $winForm.Activate(); })
$datePicker = New-Object System.Windows.Forms.DateTimePicker
$datePicker.Add_KeyPress({
if($_.KeyChar -eq [System.Char][System.Windows.Forms.Keys]::Enter){
$winForm.Close()
}
})
$winForm.Controls.Add($datePicker)
$winform.ShowDialog() | Out-null
$datePicker.Value.Date
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment