2021/05/16 #カレンダーを表示

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

#猫でもできる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) })

$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,50)
$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 = "-1 day"
$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 = "+1 day"
$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.Text = "-1 hour"
$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(90,120)
$button_R1.Text = "+1 hour"
$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)


$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,$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:20210517000524p:plain


システム的にはこのカレンダー表示をDateTimePickerと呼ぶようです

月曜日を先頭にできないかな・・

ではまた;