http://pegalabo.net/archives/VB.NET/source/findMenu.html
を参考に
Powershell でメニューを表示してみた。
コードは以下
----
[System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$form = New-Object System.Windows.Forms.Form
$MainMenu1 = New-object System.Windows.Forms.MainMenu
$MainMenuItem0 = New-object System.Windows.Forms.MenuItem
$MainMenuItem1 = New-object System.Windows.Forms.MenuItem
$ContextMenu1 = new-Object System.Windows.Forms.ContextMenu
$ContextMenuItemA0 = new-Object System.Windows.Forms.MenuItem
$ContextMenuItemA1 = new-Object System.Windows.Forms.MenuItem
$ContextMenuItemA2 = new-Object System.Windows.Forms.MenuItem
$ContextMenuItemA3 = new-Object System.Windows.Forms.MenuItem
$ContextMenuItemB0 = new-Object System.Windows.Forms.MenuItem
$MenuItem2 = new-object System.Windows.Forms.MenuItem
$MainMenuItemA0 = New-object System.Windows.Forms.MenuItem
$MainMenuItemB0 = New-object System.Windows.Forms.MenuItem
$MainMenuItemA1 = New-object System.Windows.Forms.MenuItem
$MainMenuItemA2 = New-object System.Windows.Forms.MenuItem
$MainMenuItemA21 = New-object System.Windows.Forms.MenuItem
$MainMenuItemA22 = New-object System.Windows.Forms.MenuItem
$ContextMenu1.MenuItems.AddRange(($ContextMenuItemA0,$ContextMenuItemB0))
$ContextMenuItemA0.Index = 0
$ContextMenuItemA0.MenuItems.AddRange(($ContextMenuItemA1, $ContextMenuItemA2, $ContextMenuItemA3))
$ContextMenuItemA0.Text = "A"
$ContextMenuItemA1.Index = 0
$ContextMenuItemA1.Text = "A1"
$ContextMenuItemA2.Index = 1
$ContextMenuItemA2.Text = "A2"
$ContextMenuItemA3.Index = 2
$ContextMenuItemA3.Text = "A3"
$ContextMenuItemB0.Index = 1
$ContextMenuItemB0.Text = "B"
$MainMenu1.MenuItems.AddRange(($MainMenuItem0, $MenuItem2))
$MainMenuItem0.Index = 0
$MainMenuItem0.MenuItems.AddRange(($MainMenuItemA0,$MainMenuItemB0))
$MainMenuItem0.Text = "ファイル"
$MainMenuItemA0.Index = 0
$MainMenuItemA0.MenuItems.AddRange(($MainMenuItemA1, $MainMenuItemA2))
$MainMenuItemA0.Text = "新規作成"
$MainMenuItemB0.Index = 1
$MainMenuItemB0.Text = "終了"
$MainMenuItemB0.add_Click({ $form.close() })
$MainMenuItemA1.Index = 0
$MainMenuItemA1.Text = "プロジェクト"
$MainMenuItemA2.Index = 1
$MainMenuItemA2.MenuItems.AddRange(($MainMenuItemA21, $MainMenuItemA22))
$MainMenuItemA2.Text = "ファイルだ"
$MainMenuItemA21.Index = 0
$MainMenuItemA21.Text = "ファイル1"
$MainMenuItemA22.Index = 1
$MainMenuItemA22.Text = "ファイル2"
$MenuItem2.Index = 1
$MenuItem2.Text = ""
$form.Menu = $MainMenu1
$form.ContextMenu = $ContextMenu1
$button1 = New-Object System.Windows.Forms.Button
$button1.Location = New-Object System.Drawing.Point(10, 50)
$button1.Text = "クリック!"
$button1.add_Click({ $label.Text = "hello, world"})
$button2 = New-Object System.Windows.Forms.Button
$button2.Location = New-Object System.Drawing.Point(190, 50)
$button2.Text = "終了"
$button2.add_Click({ $form.close()})
#$button2.add_Click({ [System.Windows.Forms.Application]::Exit()})
$button3 = New-Object System.Windows.Forms.Button
$button3.Location = New-Object System.Drawing.Point(100, 50)
$button3.Text = "消去"
$button3.add_Click({ $label.Text = ""})
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10, 10)
$form.Controls.AddRange(( $button1, $button2, $button3, $label))
[System.Windows.Forms.Application]::Run($form)