Skip to content

Instantly share code, notes, and snippets.

@Winand
Last active Sep 17, 2021
Embed
What would you like to do?
Проверка ввода
$glob_var = 0
Function Generate-Form {
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# Build Form
$Form = New-Object System.Windows.Forms.Form
$Form.Text = "My Form"
$Form.Size = New-Object System.Drawing.Size(200,200)
$Form.StartPosition = "CenterScreen"
$Form.Topmost = $True
$textBox = New-Object System.Windows.Forms.TextBox
$Form.Controls.Add($textBox)
# Add Button
$Button = New-Object System.Windows.Forms.Button
$Button.Location = New-Object System.Drawing.Size(35,35)
$Button.Size = New-Object System.Drawing.Size(120,23)
$Button.Text = "Проверка"
$Form.Controls.Add($Button)
#Add Button event
$Button.Add_Click({
$global:glob_var += 1
if($textBox.text) {
[System.Windows.Forms.MessageBox]::Show("Введён текст: " + $textBox.text , $global:glob_var)
} else {
[System.Windows.Forms.MessageBox]::Show("Сначала введите текст" , $global:glob_var)
}
})
#Show the Form
$form.ShowDialog()| Out-Null
} #End Function
#Call the Function
Generate-Form
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment