-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbad_combobox_event_handler.ps1
More file actions
221 lines (193 loc) · 7.31 KB
/
bad_combobox_event_handler.ps1
File metadata and controls
221 lines (193 loc) · 7.31 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#Copyright (c) 2023 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.
# origin: https://qna.habr.com/q/1282726?e=13786724#clarification_1741778
@( 'System.Drawing','System.Windows.Forms') | ForEach-Object { [void][System.Reflection.Assembly]::LoadWithPartialName($_) }
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'
function ComboInputBox {
$form = New-Object System.Windows.Forms.Form
$label_prompt = New-Object System.Windows.Forms.Label
$projectBrowseButton = New-Object System.Windows.Forms.Button
$projectTextBox = New-Object System.Windows.Forms.TextBox
$closeButton = New-Object System.Windows.Forms.Button
$eCombobox = New-Object System.Windows.Forms.ComboBox
$dcCombobox = New-Object System.Windows.Forms.ComboBox
$rCombobox = New-Object System.Windows.Forms.ComboBox
$form.SuspendLayout()
$closeButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$closeButton.FlatStyle = [System.Windows.Forms.FlatStyle]::Standard
$closeButton.Location = New-Object System.Drawing.Point (90,130)
$closeButton.Name = 'btnCancel'
$closeButton.Size = New-Object System.Drawing.Size (64,24)
$closeButton.TabIndex = 2
$closeButton.Text = 'C&lose'
$closeButton.add_click({
param([object]$sender,[System.EventArgs]$e)
$script:result.status = [System.Windows.Forms.DialogResult]::Cancel
$script:result.Text = ''
$form.Dispose()
})
$closeButton.Font = New-Object System.Drawing.Font ('Arial',10,[System.Drawing.FontStyle]::Bold,[System.Drawing.GraphicsUnit]::Point,0)
$eCombobox.Location = New-Object System.Drawing.Point (8,60)
$eCombobox.Name = 'CmBxComboBox'
$eCombobox.Size = New-Object System.Drawing.Size (60,20)
$eCombobox.TabIndex = 0
$eCombobox.Text = ''
$eCombobox.Font = New-Object System.Drawing.Font ('Arial',10,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,0)
$eCombobox.Add_TextChanged({
param(
[object]$sender,[System.EventArgs]$e)
# no op
})
$eCombobox.Add_KeyPress({
param(
[object]$sender,[System.Windows.Forms.KeyPressEventArgs]$e)
# no op
})
$eCombobox.Add_TextChanged({
param(
[object]$sender,[System.EventArgs]$e)
# no op
})
$dcCombobox.Location = New-Object System.Drawing.Point (75,60)
$dcCombobox.Name = 'CmBxComboBox'
$dcCombobox.Size = New-Object System.Drawing.Size (50,20)
$dcCombobox.TabIndex = 0
$dcCombobox.Text = ''
$dcCombobox.Font = New-Object System.Drawing.Font ('Arial',10,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,0)
$dcCombobox.Add_TextChanged({
param(
[object]$sender,[System.EventArgs]$e
)
})
$dcCombobox.Add_KeyPress({
param(
[object]$sender,[System.Windows.Forms.KeyPressEventArgs]$e
)
})
$dcCombobox.Add_TextChanged({
param(
[object]$sender,[System.EventArgs]$e
)
})
$rCombobox.Location = New-Object System.Drawing.Point (135,60)
$rCombobox.Name = 'CmBxComboBox'
$rCombobox.Size = New-Object System.Drawing.Size (220,20)
$rCombobox.TabIndex = 0
$rCombobox.Text = ''
$rCombobox.Font = New-Object System.Drawing.Font ('Arial',10,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,0)
$rCombobox.Add_TextChanged({
param([object]$sender,[System.EventArgs]$e)
})
$rCombobox.Add_KeyPress({
param(
[object]$sender,[System.Windows.Forms.KeyPressEventArgs]$e)
})
$rCombobox.Add_TextChanged({
param(
[object]$sender,[System.EventArgs]$e)
})
$form.AutoScaleBaseSize = New-Object System.Drawing.Size (5,13)
$form.ClientSize = New-Object System.Drawing.Size (438,158)
$form.Controls.AddRange(@( $eCombobox,$dcCombobox,$rCombobox,$closeButton))
$form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$form.MaximizeBox = $false
$form.MinimizeBox = $false
$form.Name = 'ComboBoxDialog'
$form.ResumeLayout($false)
$form.AcceptButton = $launchButton
$script:result.status = [System.Windows.Forms.DialogResult]::Ignore
$form.Name = 'Form1'
$form.ResumeLayout($false)
$form.Topmost = $true
$form.Add_Shown({ $form.Activate() })
$form.Add_Closing({
param(
[object]$sender,[System.ComponentModel.CancelEventArgs]$e
)
# prevent the Closing event from closing the form
# The 'Cancel' button will still do
$e.Cancel = $true
})
[void]$form.ShowDialog($caller)
$form.Dispose()
$form = $null
return $script:result
}
$o = ComboInputBox
<#
private void comboBoxMySqlFilter(object sender, EventArgs e)
{
ComboBox comboBox = (ComboBox)sender;
string selectedValue = comboBox.SelectedItem?.ToString();
List<(ComboBox comboBox, string propertyName)> filterMappingsMySql = new List<(ComboBox, string)>
{
(cbFindServerMySql, "server"),
(cbFindModelMySql, "model"),
(cbFindOperatorMySql, "mobileoperator"),
};
foreach (var mapping in filterMappingsMySql)
{
if (sender is ComboBox cb && cb == mapping.comboBox)
{
List<deviceMySql> filteredDevices = deviceMySql.dgvDevices
.Where(d => d.GetType().GetProperty(mapping.propertyName)?
.GetValue(d)?.ToString() == cb.Text)
.ToList();
dgvMySql.DataSource = filteredDevices;
}
else
{
mapping.comboBox.Text = null;
}
}
}
#>
function shared_handler{
param(
[object]$sender,[System.EventArgs]$e
)
[System.Windows.Forms.ComboBox] $comboBox = (System.Windows.Forms.ComboBox) $sender
[String] $selectedValue = $comboBox.SelectedItem.ToString()
# prevent the Closing event from closing the form
# The 'Cancel' button will still do
$e.Cancel = $true
}