2021/04/17 #ラジオボタンを表示

皆様おはようございます、

#猫でもできるPowerShell(備忘録)

#ラジオボタンを表示

 <# 元ネタ
https://www.atmarkit.co.jp/ait/articles/0607/26/news118_3.html
#>
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$Form = New-Object System.Windows.Forms.Form
$Form.Size = "300,400"
$Form.StartPosition = "CenterScreen"
$Form.Text = "コントロール配置テスト"

$button = New-Object System.Windows.Forms.Button
$button.Location = New-Object System.Drawing.Point(180,10)
$button.Text = "押すな"
$button.add_Click({ $label.Text = "Get-Date -Format G"; $textbox.text = (iex $label.Text) })

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 10)
$label.Size = New-Object System.Drawing.Size(180,20)

#$form.Controls.AddRange*1


$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,60)
$textBox.Size = New-Object System.Drawing.Size(180,20)

$button_L = New-Object System.Windows.Forms.Button
$button_L.Location = New-Object System.Drawing.Point(10,160)
$button_L.Text = "戻る"
$button_L.add_Click({ $textbox.text = (get-date $textbox.text ).adddays(-1) })
$button_R = New-Object System.Windows.Forms.Button
$button_R.Location = New-Object System.Drawing.Point(80,160)
$button_R.Text = "進む"
$button_R.add_Click({ $textbox.text = (get-date $textbox.text ).adddays(+1) })


$grpBox = New-Object System.Windows.Forms.GroupBox
$grpBox.Location = New-Object System.Drawing.Point(10,199)
$grpBox.size = New-Object System.Drawing.Size(240,120)
$grpBox.text = "ラジオボタン"

$RadButton1 = New-Object System.Windows.Forms.RadioButton
$RadButton1.Location = New-Object System.Drawing.Point(10,20)
$RadButton1.size = New-Object System.Drawing.Size(80,30)
$RadButton1.Text = "Option1"
$RadButton1.Checked = $True

$RadButton2 = New-Object System.Windows.Forms.RadioButton
$RadButton2.Location = New-Object System.Drawing.Point(10,60)
$RadButton2.size = New-Object System.Drawing.Size(80,30)
$RadButton2.Text = "Option2"

$grpBox.Controls.AddRange(@($RadButton1,$RadButton2))


$form.Controls.AddRange(@($button,$label,$textBox,$button_L,$button_R,$grpBox))

#[System.Windows.Forms.Application]::Run($form)
$Form.ShowDialog()

 

何だか道具箱みたいになってきました

ではまた;

*1:$button, $label