2021/04/30 #トグルボタンを表示

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

#猫でもできる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 = "500,390"
$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( ($button, $label) )

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

$button_L = New-Object System.Windows.Forms.Button
$button_L.Location = New-Object System.Drawing.Point(10,90)
$button_L.Text = "戻る"
$button_L.add_Click({ $textbox.text = Get-Date( (Get-Date $textbox.text).AddDays(-1) ) -Format G })
$button_R = New-Object System.Windows.Forms.Button
$button_R.Location = New-Object System.Drawing.Point(90,90)
$button_R.Text = "進む"
$button_R.add_Click({ $textbox.text = Get-Date( (Get-Date $textbox.text).AddDays(+1) ) -Format G })


$grpBox = New-Object System.Windows.Forms.GroupBox
$grpBox.Location = New-Object System.Drawing.Point(10,140)
$grpBox.size = New-Object System.Drawing.Size(240,100)
$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))

$NumCtl = New-Object System.Windows.Forms.NumericUpDown
$NumCtl.location = New-Object System.Drawing.Point(10,260)
$NumCtl.Size = New-Object System.Drawing.Size(170,40)
$NumCtl.TextAlign = "Center"
$NumCtl.UpDownAlign = "Right"
$NumCtl.Maximum = "2050"
$NumCtl.Minimum = "1999"
$NumCtl.Text = "2021"

$toggle = New-Object System.Windows.Forms.CheckBox
$toggle.location = New-Object System.Drawing.Point(270,70)
$toggle.size = New-Object System.Drawing.Size(80,25)
$toggle.Text = "Value0"
$toggle.Appearance = "Button"
$toggle.FlatStyle = "System"
$v = {
IF ( $toggle.text -eq "Value0")
{ $toggle.text = "Value1"
} else{ $toggle.text = "Value0"
}
}
$toggle.Add_CheckedChanged($v)


$ChkBox = New-Object System.Windows.Forms.CheckedListBox
$ChkBox.Location = New-Object System.Drawing.Point(270,140)
$ChkBox.Size = New-Object System.Drawing.Size(120,120)
$ChkBox.text = "ネタリスト"
$ChkBox.Items.AddRange( ("大トロ","甘海老","炙りサーモン") )

$Cmb = New-Object System.Windows.Forms.Combobox
$Cmb.Location = New-Object System.Drawing.Point(270,270)
$Cmb.size = New-Object System.Drawing.Size(120,30)
$Cmb.DropDownStyle = "DropDown"
$Cmb.Items.Add("大トロ")
$Cmb.Items.Add("甘海老")
$Cmb.Items.Add("炙りサーモン")

$form.Controls.AddRange(@($button,$label,$textBox,$button_L,$button_R,$grpBox,$NumCtl,$toggle,$ChkBox,$Cmb))
#[System.Windows.Forms.Application]::Run($form)
$Form.ShowDialog()

 

f:id:TPTPTb:20210501081712p:plain

f:id:TPTPTb:20210501081733p:plain

今日はトグルボタン(オブジェクト名はcheckbox)です

押した時にボタンの色が変わりますが少しわかりにくいので要改善・・

ではまた;