一つ上へ
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# フォーム作成
$form = New-Object System.Windows.Forms.Form
$form.Text = "サンプルフォーム"
$form.Size = New-Object System.Drawing.Size(400,300)
# ラジオボタン
$radio1 = New-Object System.Windows.Forms.RadioButton
$radio1.Text = "選択肢 1"
$radio1.Location = New-Object System.Drawing.Point(20,20)
$radio2 = New-Object System.Windows.Forms.RadioButton
$radio2.Text = "選択肢 2"
$radio2.Location = New-Object System.Drawing.Point(20,50)
# チェックボックス
$check = New-Object System.Windows.Forms.CheckBox
$check.Text = "同意します"
$check.Location = New-Object System.Drawing.Point(20,80)
# プルダウン(コンボボックス)
$combo = New-Object System.Windows.Forms.ComboBox
$combo.Location = New-Object System.Drawing.Point(20,120)
$combo.Items.AddRange(@("選択肢A","選択肢B","選択肢C"))
# OKボタン
$okButton = New-Object System.Windows.Forms.Button
$okButton.Text = "OK"
$okButton.Location = New-Object System.Drawing.Point(20,160)
$okButton.Add_Click({
[System.Windows.Forms.MessageBox]::Show("ラジオ: " +
($(if ($radio1.Checked) { $radio1.Text } elseif ($radio2.Checked) { $radio2.Text } else { "未選択" })) +
"`nチェック: " + $check.Checked +
"`nプルダウン: " + $combo.SelectedItem)
})
# コントロールを追加
$form.Controls.Add($radio1)
$form.Controls.Add($radio2)
$form.Controls.Add($check)
$form.Controls.Add($combo)
$form.Controls.Add($okButton)
# フォームを表示
$form.ShowDialog()