PowerShellスクリプトを作成し、メインインターフェイスでタブ付きレイアウトを使用できるようにしようとしています。
タブを上に非表示にし、メニューストリップのボタンを使用してタブを切り替える以外は、機能させたいすべての機能を取得しました。
私はすでにメニューストリップを正常に作成し、タブを上に非表示にしましたが、メニューのボタンで別のタブを選択する方法がわかりません。
誰かがこれを行う方法はありますか?
例 :
メニューストリップ:Control1 Control2タブコントロールのタブページ:Tabpage1 Tabpage2
Control1でTabpage1、Control2でTabpage2のタブページを表示するにはどうすればよいですか?
以下のコード:
#----------------------------------------------
#region Application Functions
#----------------------------------------------
function OnApplicationLoad {
#Note: This function is not called in Projects
#Note: This function runs before the form is created
#Note: To get the script directory in the Packager use: Split-Path $hostinvocation.MyCommand.path
#Note: To get the console output in the Packager (Windows Mode) use: $ConsoleOutput (Type: System.Collections.ArrayList)
#Important: Form controls cannot be accessed in this function
#TODO: Add snapins and custom code to validate the application load
return $true #return true for success or false for failure
}
function OnApplicationExit {
#Note: This function is not called in Projects
#Note: This function runs after the form is closed
#TODO: Add custom code to clean up and unload snapins when the application exits
$script:ExitCode = 0 #Set the exit code for the Packager
}
#endregion Application Functions
#----------------------------------------------
# Generated Form Function
#----------------------------------------------
function Call-example_pff {
#----------------------------------------------
#region Import the Assemblies
#----------------------------------------------
[void][reflection.assembly]::Load("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
[void][reflection.assembly]::Load("System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
[void][reflection.assembly]::Load("System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
#endregion Import Assemblies
#----------------------------------------------
#region Generated Form Objects
#----------------------------------------------
[System.Windows.Forms.Application]::EnableVisualStyles()
$form1 = New-Object 'System.Windows.Forms.Form'
$tabcontrol1 = New-Object 'System.Windows.Forms.TabControl'
$tabpage1 = New-Object 'System.Windows.Forms.TabPage'
$tabpage2 = New-Object 'System.Windows.Forms.TabPage'
$menustrip1 = New-Object 'System.Windows.Forms.MenuStrip'
$control1ToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$control2ToolStripMenuItem = New-Object 'System.Windows.Forms.ToolStripMenuItem'
$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
#endregion Generated Form Objects
#----------------------------------------------
# User Generated Script
#----------------------------------------------
$form1_Load={
#TODO: Initialize Form Controls here
}
# --End User Generated Script--
#----------------------------------------------
#region Generated Events
#----------------------------------------------
$Form_StateCorrection_Load=
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
}
$Form_Cleanup_FormClosed=
{
#Remove all event handlers from the controls
try
{
$form1.remove_Load($form1_Load)
$form1.remove_Load($Form_StateCorrection_Load)
$form1.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch [Exception]
{ }
}
#endregion Generated Events
#----------------------------------------------
#region Generated Form Code
#----------------------------------------------
#
# form1
#
$form1.Controls.Add($tabcontrol1)
$form1.Controls.Add($menustrip1)
$form1.ClientSize = '842, 355'
$form1.MainMenuStrip = $menustrip1
$form1.Name = "form1"
$form1.Text = "Form"
$form1.add_Load($form1_Load)
#
# tabcontrol1
#
$tabcontrol1.Controls.Add($tabpage1)
$tabcontrol1.Controls.Add($tabpage2)
$tabcontrol1.Location = '9, 71'
$tabcontrol1.Name = "tabcontrol1"
$tabcontrol1.SelectedIndex = 0
$tabcontrol1.Size = '811, 256'
$tabcontrol1.TabIndex = 1
#
# tabpage1
#
$tabpage1.Location = '4, 22'
$tabpage1.Name = "tabpage1"
$tabpage1.Padding = '3, 3, 3, 3'
$tabpage1.Size = '803, 230'
$tabpage1.TabIndex = 0
$tabpage1.Text = "tabpage1"
$tabpage1.UseVisualStyleBackColor = $True
#
# tabpage2
#
$tabpage2.Location = '4, 22'
$tabpage2.Name = "tabpage2"
$tabpage2.Padding = '3, 3, 3, 3'
$tabpage2.Size = '803, 230'
$tabpage2.TabIndex = 1
$tabpage2.Text = "tabpage2"
$tabpage2.UseVisualStyleBackColor = $True
#
# menustrip1
#
$menustrip1.BackColor = 'Red'
[void]$menustrip1.Items.Add($control1ToolStripMenuItem)
[void]$menustrip1.Items.Add($control2ToolStripMenuItem)
$menustrip1.Location = '0, 0'
$menustrip1.Name = "menustrip1"
$menustrip1.Size = '842, 24'
$menustrip1.TabIndex = 0
$menustrip1.Text = "menustrip1"
#
# control1ToolStripMenuItem
#
$control1ToolStripMenuItem.Name = "control1ToolStripMenuItem"
$control1ToolStripMenuItem.Size = '65, 20'
$control1ToolStripMenuItem.Text = "Control1"
#
# control2ToolStripMenuItem
#
$control2ToolStripMenuItem.Name = "control2ToolStripMenuItem"
$control2ToolStripMenuItem.Size = '65, 20'
$control2ToolStripMenuItem.Text = "Control2"
#endregion Generated Form Code
#----------------------------------------------
#Save the initial state of the form
$InitialFormWindowState = $form1.WindowState
#Init the OnLoad event to correct the initial state of the form
$form1.add_Load($Form_StateCorrection_Load)
#Clean up the control events
$form1.add_FormClosed($Form_Cleanup_FormClosed)
#Show the Form
return $form1.ShowDialog()
} #End Function
#Call OnApplicationLoad to initialize
if((OnApplicationLoad) -eq $true)
{
#Call the form
Call-example_pff | Out-Null
#Perform cleanup
OnApplicationExit
}