2021/10/23 #サイズを変更してボタンを増やす

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

#猫でもできる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 = New-Object System.Drawing.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) })


$button_G0 = New-Object System.Windows.Forms.Button
$button_G0.Location = New-Object System.Drawing.Point(10,10)
$button_G0.Size = New-Object System.Drawing.Size(20,20) 
$button_G0.Text = "g" 
$button_G0.add_Click({ $label.Text = "Get-Date -Format g"; $textbox.text = (iex $label.Text) })

$button_G1 = New-Object System.Windows.Forms.Button
$button_G1.Location = New-Object System.Drawing.Point(40,10)
$button_G1.Size = New-Object System.Drawing.Size(20,20) 
$button_G1.Text = "G" 
$button_G1.add_Click({ $label.Text = "Get-Date -Format G"; $textbox.text = (iex $label.Text) })

$button_F0 = New-Object System.Windows.Forms.Button
$button_F0.Location = New-Object System.Drawing.Point(70,10)
$button_F0.Size = New-Object System.Drawing.Size(20,20) 
$button_F0.Text = "f" 
$button_F0.add_Click({ $label.Text = "Get-Date -Format f"; $textbox.text = (iex $label.Text) })

$button_F1 = New-Object System.Windows.Forms.Button
$button_F1.Location = New-Object System.Drawing.Point(100,10)
$button_F1.Size = New-Object System.Drawing.Size(20,20) 
$button_F1.Text = "F" 
$button_F1.add_Click({ $label.Text = "Get-Date -Format F"; $textbox.text = (iex $label.Text) })

$button_S0 = New-Object System.Windows.Forms.Button
$button_S0.Location = New-Object System.Drawing.Point(130,10)
$button_S0.Size = New-Object System.Drawing.Size(20,20) 
$button_S0.Text = "s" 
$button_S0.add_Click({ $label.Text = "Get-Date -Format s"; $textbox.text = (iex $label.Text) })

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 40)
$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(55,90)
$button_L.Size = New-Object System.Drawing.Size(40,20) 
$button_L.Text = "-1 d"
$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(105,90)
$button_R.Size = New-Object System.Drawing.Size(40,20) 
$button_R.Text = "+1 d"
$button_R.add_Click({ $textbox.text =  Get-Date( (Get-Date $textbox.text).AddDays(+1) ) -Format G })
$button_L1 = New-Object System.Windows.Forms.Button
$button_L1.Location = New-Object System.Drawing.Point(10,120)
$button_L1.Size = New-Object System.Drawing.Size(40,20) 
$button_L1.Text = "-1 h"
$button_L1.add_Click({ $textbox.text =  Get-Date( (Get-Date $textbox.text).AddHours(-1) ) -Format G })
$button_R1 = New-Object System.Windows.Forms.Button
$button_R1.Location = New-Object System.Drawing.Point(150,120)
$button_R1.Size = New-Object System.Drawing.Size(40,20) 
$button_R1.Text = "+1 h"
$button_R1.add_Click({ $textbox.text =  Get-Date( (Get-Date $textbox.text).AddHours(+1) ) -Format G })


$grpBox = New-Object System.Windows.Forms.GroupBox
$grpBox.Location = New-Object System.Drawing.Point(10,160)
$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,280)
$NumCtl.Size = New-Object System.Drawing.Size(170,40)
$NumCtl.TextAlign = "Center"
$NumCtl.UpDownAlign = "Right"
$NumCtl.Maximum = "2050"
$NumCtl.Minimum = "1999"
$NumCtl.Text = "2021"

$picker = New-Object System.Windows.Forms.DatetimePicker
$picker.location = New-Object System.Drawing.Point(270,50)
$picker.size = New-Object System.Drawing.Size(150,35)
#$Picker.FirstDayOfWeek = DayOfWeek.Monday


$toggle = New-Object System.Windows.Forms.CheckBox
$toggle.location = New-Object System.Drawing.Point(270,90)
$toggle.size = New-Object System.Drawing.Size(80,35)
$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)
#>

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

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

$Cmb = New-Object System.Windows.Forms.Combobox
$Cmb.Location = New-Object System.Drawing.Point(270,300)
$Cmb.size = New-Object System.Drawing.Size(120,30)
# $Cmb.DropDownStyle = "DropDown"

$Cmb.DropDownStyle = "DropDownList"
 [void] $Cmb.Items.Add("大トロ")
 [void] $Cmb.Items.Add("甘海老")
 [void] $Cmb.Items.Add("炙りサーモン")

$CTLs = @($button,$button_G0,$button_G1,$button_F0,$button_F1,$button_S0,
$label,$textBox,$button_L,$button_R,$button_L1,$button_R1,
$grpBox,$NumCtl,$picker,$toggle,$ListBox,$ChkBox,$Cmb)
$form.Controls.AddRange($CTLs)
#[System.Windows.Forms.Application]::Run($form)
$Form.ShowDialog()

f:id:TPTPTb:20211024000647p:plain


過去何度か載せたフォームですが
±1日、±1時間に加えて±1ヶ月、±1分のボタンを作ろうと思いました
ボタンの .sizeプロパティで少し縮めて間を空けただけ
続きは明日以降で w
ではまた;