-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar_basic_1.ps1
More file actions
134 lines (104 loc) · 3.54 KB
/
calendar_basic_1.ps1
File metadata and controls
134 lines (104 loc) · 3.54 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#Copyright (c) 2014 Serguei Kouzmine
#
#Permission is hereby granted, free of charge, to any person obtaining a copy
#of this software and associated documentation files (the "Software"), to deal
#in the Software without restriction, including without limitation the rights
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is
#furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in
#all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
#THE SOFTWARE.
function PromptCalendar (
[string]$title,
[string]$message,
[object]$caller
) {
@('System.Data', 'System.Drawing','System.Windows.Forms') | foreach-object { [void] [System.Reflection.Assembly]::LoadWithPartialName($_) }
[string]$result = ''
$f = New-Object System.Windows.Forms.Form
$f.Text = $title
$f.Size = New-Object System.Drawing.Size(650,120)
$f.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen
$m = New-Object System.Windows.Forms.MonthCalendar
$b = New-Object System.Windows.Forms.Button
$f.SuspendLayout()
$m.FirstDayOfWeek = [System.Windows.Forms.Day]::Thursday
$m.Location = New-Object System.Drawing.Point(16, 16)
$m.Name = 'monthCalendar1'
$m.ShowTodayCircle = $false
$m.ShowWeekNumbers = $true
$m.TabIndex = 0
$b.Location = New-Object System.Drawing.Point(48, 184)
$b.Name = 'button1'
$b.Size = New-Object System.Drawing.Size(128, 23)
$b.TabIndex = 1
$b.Text = 'Selection Range'
$f.AutoScaleBaseSize = New-Object System.Drawing.Size(5, 13)
$f.ClientSize = New-Object System.Drawing.Size(232, 213)
$f.Controls.AddRange(@( $b, $m))
$f.Name = 'Calendar'
$f.Text = 'Calendar Control'
$f.ResumeLayout($false)
$Calendar_Load = $f.Add_Load
$Calendar_Load.Invoke({
param(
[object]$sender,
[System.EventArgs]$e
)
[string ]$str = $m.Text.ToString()
})
$b_Click = $b.Add_Click
$b_Click.Invoke({
param(
[object]$sender,
[System.EventArgs]$e
)
[SelectionRange]$sr = $m.SelectionRange
[SelectionRange]$st = $sr.Start
[SelectionRange]$se = $sr.End
$caller.Data = ( "RANGE START = {0}`nRANGE END = {1}" -f $st.ToString() , $se.ToString() );
})
$f.Topmost = $True
$f.Add_Shown({ $f.Activate() })
[void]$f.ShowDialog([win32window]($caller))
$f.Dispose()
}
Add-Type -TypeDefinition @"
// "
using System;
using System.Windows.Forms;
public class Win32Window : IWin32Window
{
private IntPtr _hWnd;
private string _data;
public string Data
{
get { return _data; }
set { _data = value; }
}
public Win32Window(IntPtr handle)
{
_hWnd = handle;
}
public IntPtr Handle
{
get { return _hWnd; }
}
}
"@ -ReferencedAssemblies 'System.Windows.Forms.dll'
$DebugPreference = 'Continue'
$title = 'Question'
$message = "Continue to Next step?"
$caller = New-Object Win32Window -ArgumentList ([System.Diagnostics.Process]::GetCurrentProcess().MainWindowHandle)
PromptCalendar -Title $title -Message $message -caller $caller
$result = $caller.Data
Write-Debug ("Result is : {0} " -f $caller.Data)