如何隐藏Powershell GUI上的标签?

时间:2012-12-26 09:50:45

标签: powershell powershell-v2.0 powershell-v3.0

好的,我创建了一个powershell脚本,我试图让主界面使用标签式布局。我得到了我想要的所有功能,除了我想隐藏顶部的标签并使用侧面的按钮来切换标签。我已经成功地选择了不同选项卡的侧面按钮,但我无法弄清楚如何隐藏顶部的标签?任何人都有办法怎么做???

图片说它最好:  enter image description here

参考文献:

  1. http://msdn.microsoft.com/en-us/library/system.windows.forms.tabpage%28v=vs.90%29.aspx
  2. http://msdn.microsoft.com/en-us/library/system.windows.forms.tabpage.tabpagecontrolcollection%28v=vs.90%29.aspx
  3. http://msdn.microsoft.com/en-us/library/system.windows.forms.tabrenderer%28v=vs.90%29.aspx
  4. http://msdn.microsoft.com/en-us/library/system.windows.forms.tabcontrol%28v=vs.90%29.aspx
  5. 更新

    找到此链接(WinForms Hiding TabControl Headers),但它的Vb.net。一直在玩它一个小时左右但到目前为止没有运气>。>

    我的代码:

    #Generated Form Function
    function GenerateForm {
    
    #region Import the Assemblies
    [reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
    [reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
    
    #region Generated Form Objects
    $MainMenu = New-Object System.Windows.Forms.Form
    $InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
    
    #Panels
    $Panel1 = New-Object System.Windows.Forms.Panel
    $Panel2 = New-Object System.Windows.Forms.Panel
    
    #Buttons
    $HomeButton = New-Object System.Windows.Forms.Button
    $ScriptSettingsButton = New-Object System.Windows.Forms.Button
    $COTSButton = New-Object System.Windows.Forms.Button
    $MicrosoftButton = New-Object System.Windows.Forms.Button
    $ConfigureButton = New-Object System.Windows.Forms.Button
    $MiscToolsButton = New-Object System.Windows.Forms.Button
    $TabControl = New-Object System.Windows.Forms.TabControl
    
    #Misc Items
    $ProgressBar = New-Object System.Windows.Forms.ProgressBar
    $StatusBar = New-Object System.Windows.Forms.StatusBar
    
    #Tabs
    $TabControl = New-object System.Windows.Forms.TabControl
    $HomeTab = New-Object System.Windows.Forms.TabPage
    $ScriptSettingsTab = New-Object System.Windows.Forms.TabPage
    
    #----------------------------------------------
    #Generated Event Script Blocks
    #----------------------------------------------
    #Provide Custom Code for events specified in PrimalForms.
    #Unknown
    $handler_MainMenu_Load =
    $OnLoadForm_StateCorrection= { $MainMenu.WindowState = $InitialFormWindowState }
    
    #Buttons
    $HomeButton_OnClick = { $TabControl.SelectTab($HomeTab) }
    $ScriptSettingsButton_OnClick = { $TabControl.SelectTab($ScriptSettingsTab) }
    $COTSButton_OnClick = {}
    $MicrosoftButton_OnClick = {  }
    $ConfigureButton_OnClick = {}
    $MiscToolsButton_OnClick = {}
    
    $Hometab.Enabled = 
    
    $statusBar1_PanelClick= 
    
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 474
    $System_Drawing_Size.Width = 665
    $MainMenu.ClientSize = $System_Drawing_Size
    $MainMenu.DataBindings.DefaultDataSourceUpdateMode = 0
    $MainMenu.Name = "MainMenu"
    $MainMenu.Text = "Patching Script"
    $MainMenu.TopMost = $True
    $MainMenu.add_Load($handler_form1_Load)
    
    # == Home Button == #
    $HomeButton.Name = "HomeButton"
    $HomeButton.Text = "Home"
    $HomeButton.TabIndex = 2
    $HomeButton.UseVisualStyleBackColor = $True
    $HomeButton.add_Click($HomeButton_OnClick)
    $HomeButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 69
    $HomeButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $HomeButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($HomeButton)
    
    # == Script Settings Button == #
    $ScriptSettingsButton.Name = "ScriptSettingsButton"
    $ScriptSettingsButton.Text = "Script Settings"
    $ScriptSettingsButton.TabIndex = 3
    $ScriptSettingsButton.UseVisualStyleBackColor = $True
    $ScriptSettingsButton.add_Click($ScriptSettingsButton_OnClick)
    $ScriptSettingsButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 110
    $ScriptSettingsButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $ScriptSettingsButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($ScriptSettingsButton)
    
    # == COTS Button == #
    $COTSButton.Name = "COTSButton"
    $COTSButton.Text = "C.O.T.S."
    $COTSButton.TabIndex = 4
    $COTSButton.UseVisualStyleBackColor = $True
    $COTSButton.add_Click($COTSButton_OnClick)
    $COTSButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 151
    $COTSButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $COTSButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($COTSButton)
    
    # == Microsoft Button == #
    $MicrosoftButton.Name = "MicrosoftButton"
    $MicrosoftButton.Text = "Microsoft Patches"
    $MicrosoftButton.TabIndex = 5
    $MicrosoftButton.UseVisualStyleBackColor = $True
    $MicrosoftButton.add_Click($MicrosoftButton_OnClick)
    $MicrosoftButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 192
    $MicrosoftButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $MicrosoftButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($MicrosoftButton)
    
    # == Configure Button == #
    $ConfigureButton.Name = "ConfigureButton"
    $ConfigureButton.Text = "Configure Script"
    $ConfigureButton.TabIndex = 6
    $ConfigureButton.Location = $System_Drawing_Point
    $ConfigureButton.UseVisualStyleBackColor = $True
    $ConfigureButton.add_Click($ConfigureButton_OnClick)
    $ConfigureButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 233
    $ConfigureButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $ConfigureButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($ConfigureButton)
    
    # == Misc Tools Button == #
    $MiscToolsButton.Name = "MiscToolsButton"
    $MiscToolsButton.Text = "Misc Tools"
    $MiscToolsButton.TabIndex = 7
    $MiscToolsButton.UseVisualStyleBackColor = $True
    $MiscToolsButton.add_Click($MiscToolsButton_OnClick)
    $MiscToolsButton.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 12
    $System_Drawing_Point.Y = 274
    $MiscToolsButton.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 35
    $System_Drawing_Size.Width = 100
    $MiscToolsButton.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($MiscToolsButton)
    
    # == Tab Control == #
    $TabControl.Name = "TabControl"
    $TabControl.TabIndex = 4
    $TabControl.SelectedIndex = 0
    $TabControl.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 118
    $System_Drawing_Point.Y = 70
    $TabControl.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 374
    $System_Drawing_Size.Width = 535
    $TabControl.Size = $System_Drawing_Size
    
    $MainMenu.Controls.Add($TabControl)
    
    
    # == Home Tab == #
    $HomeTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $HomeTab.Name = "HomeTab"
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 4
    $System_Drawing_Point.Y = 22
    $HomeTab.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 205
    $System_Drawing_Size.Width = 445
    $HomeTab.Size = $System_Drawing_Size
    $HomeTab.TabIndex = 2
    $HomeTab.Text = "Tab2"
    $HomeTab.UseVisualStyleBackColor = $True
    
    $TabControl.Controls.Add($HomeTab)
    
    
    # == Script Settings Tab == #
    $ScriptSettingsTab.DataBindings.DefaultDataSourceUpdateMode = 0
    $ScriptSettingsTab.Name = "ScriptSettingsTab"
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 4
    $System_Drawing_Point.Y = 22
    $ScriptSettingsTab.Location = $System_Drawing_Point
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 205
    $System_Drawing_Size.Width = 445
    $ScriptSettingsTab.Size = $System_Drawing_Size
    $ScriptSettingsTab.TabIndex = 2
    $ScriptSettingsTab.Text = "Tab2"
    $ScriptSettingsTab.UseVisualStyleBackColor = $True
    
    $TabControl.Controls.Add($ScriptSettingsTab)
    
    # == Panel 1 == #
    #$panel1.DataBindings.DefaultDataSourceUpdateMode = 0
    #$System_Drawing_Point = New-Object System.Drawing.Point
    #$System_Drawing_Point.X = 118
    #$System_Drawing_Point.Y = 70
    #$panel1.Location = $System_Drawing_Point
    #$panel1.Name = "panel1"
    #$System_Drawing_Size = New-Object System.Drawing.Size
    #$System_Drawing_Size.Height = 374
    #$System_Drawing_Size.Width = 535
    #$panel1.Size = $System_Drawing_Size
    #$panel1.TabIndex = 8
    #$Panel1.BackColor = [System.Drawing.Color]::CornflowerBlue
    
    #$MainMenu.Controls.Add($panel1)
    
    # == Progress Bar == #
    $progressBar.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 589
    $System_Drawing_Point.Y = 458
    $progressBar.Location = $System_Drawing_Point
    $progressBar.Name = "progressBar"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 15
    $System_Drawing_Size.Width = 75
    $progressBar.Size = $System_Drawing_Size
    $progressBar.TabIndex = 0
    
    $MainMenu.Controls.Add($progressBar)
    
    # == Status bar == #
    $StatusBar.DataBindings.DefaultDataSourceUpdateMode = 0
    $System_Drawing_Point = New-Object System.Drawing.Point
    $System_Drawing_Point.X = 0
    $System_Drawing_Point.Y = 456
    $StatusBar.Location = $System_Drawing_Point
    $StatusBar.Name = "StatusBar"
    $System_Drawing_Size = New-Object System.Drawing.Size
    $System_Drawing_Size.Height = 18
    $System_Drawing_Size.Width = 665
    $StatusBar.Size = $System_Drawing_Size
    $StatusBar.TabIndex = 1
    $StatusBar.Text = "statusBar1"
    $StatusBar.add_PanelClick($statusBar_PanelClick)
    
    $MainMenu.Controls.Add($StatusBar)
    
    # == Save and Open Form == #
    $InitialFormWindowState = $MainMenu.WindowState
    $MainMenu.add_Load($OnLoadForm_StateCorrection)
    $MainMenu.ShowDialog()| Out-Null
    
    } #End Function
    
    #Call the Function
    GenerateForm
    

1 个答案:

答案 0 :(得分:2)

将以下内容添加到TabControl属性设置部分:

$TabSizeMode = New-object System.Windows.Forms.TabSizeMode
$TabSizeMode = "Fixed"
$TabControl.SizeMode =$TabSizeMode
$TabControl.ItemSize = New-Object System.Drawing.Size(0, 1)
$TabAppearance = New-object System.Windows.Forms.TabAppearance
$TabAppearance = "Buttons"
$TabControl.Appearance = $TabAppearance

来自Kevin Dente's Blog

要显示标签正确切换,您可以添加:

$HomeTab.BackColor = "White"
$ScriptSettingsTab.BackColor = "Red"