Collapsible Groupbox?

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of keith noble keith noble 3 months, 1 week ago.

  • Author
    Posts
  • #52091
    Profile photo of keith noble
    keith noble
    Participant

    I am wondering if it is possible to create a collapsible groupbox. I have been looking around and can't find an actual answer for PowerShell.

    What I am trying to see is if I have 2 group boxes in my GUI, one for Admin Tools and one for Console Tools. If the user clicks admin tools it expands and shows some radio buttons that the user can pick. And if he clicks it again it collapses it back to where it was at. Same for the Console Tools box.

    This is what my groupbox.text code currently looks like:

    $groupBox = New-Object System.Windows.Forms.GroupBox
    $groupBox.Location = New-Object System.Drawing.Size(270,25)
    $groupBox.size = New-Object System.Drawing.Size(115,100)
    $groupBox.text = "Options:"

    I was looking into autosize but that just expands the group boxes as I add more options.
    $Form.Controls.Add($groupBox)

  • #52094
    Profile photo of Dan Potter
    Dan Potter
    Participant

    use a split container, and hide one.

    • This reply was modified 3 months, 2 weeks ago by Profile photo of Dan Potter Dan Potter.
  • #52098
    Profile photo of Dan Potter
    Dan Potter
    Participant

    This forum keeps stripping out code with greaterthan lessthan. add them to the button click event.

    #------------------------------------------------------------------------
    # Source File Information (DO NOT MODIFY)
    # Source ID: 2b82cd8c-486a-444e-9154-6aacdd389a5c
    # Source File: C:\Users\\Documents\SAPIEN\Files\splitcontainer.psf
    #------------------------------------------------------------------------
    
    
    #----------------------------------------------
    #region Application Functions
    #----------------------------------------------
    
    #endregion Application Functions
    
    #----------------------------------------------
    # Generated Form Function
    #----------------------------------------------
    function Call-splitcontainer_psf {
    
    	#----------------------------------------------
    	#region Import the Assemblies
    	#----------------------------------------------
    	[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.DirectoryServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    	[void][reflection.assembly]::Load('System.ServiceProcess, 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'
    	$splitcontainer1 = New-Object 'System.Windows.Forms.SplitContainer'
    	$button1 = New-Object 'System.Windows.Forms.Button'
    	$groupbox1 = New-Object 'System.Windows.Forms.GroupBox'
    	$labelPanelTwo = New-Object 'System.Windows.Forms.Label'
    	$InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	#endregion Generated Form Objects
    
    	#----------------------------------------------
    	# User Generated Script
    	#----------------------------------------------
    	
    	$form1_Load={
    		
    	}
    	
    	$button1_Click = {
    		
    		if ($splitcontainer1.Panel1Collapsed -eq $true) {
    			
    			$splitcontainer1.Panel1Collapsed = $false
    			$button1.Text = 'gt'
    			
    		} else {
    			
    			$splitcontainer1.Panel1Collapsed = $true
    			$button1.Text = 'lt'
    		}
    		
    	}
    	
    	# --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
    		{
    			$button1.remove_Click($button1_Click)
    			$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.SuspendLayout()
    	$splitcontainer1.SuspendLayout()
    	#
    	# form1
    	#
    	$form1.Controls.Add($splitcontainer1)
    	$form1.Controls.Add($button1)
    	$form1.AutoScaleDimensions = '6, 13'
    	$form1.AutoScaleMode = 'Font'
    	$form1.ClientSize = '613, 539'
    	$form1.Name = 'form1'
    	$form1.Text = 'Form'
    	$form1.add_Load($form1_Load)
    	#
    	# splitcontainer1
    	#
    	$splitcontainer1.BorderStyle = 'Fixed3D'
    	$splitcontainer1.Location = '33, 12'
    	$splitcontainer1.Name = 'splitcontainer1'
    	[void]$splitcontainer1.Panel1.Controls.Add($groupbox1)
    	[void]$splitcontainer1.Panel2.Controls.Add($labelPanelTwo)
    	$splitcontainer1.Size = '568, 504'
    	$splitcontainer1.SplitterDistance = 189
    	$splitcontainer1.TabIndex = 1
    	#
    	# button1
    	#
    	$button1.Location = '12, 12'
    	$button1.Name = 'button1'
    	$button1.Size = '15, 504'
    	$button1.TabIndex = 0
    	$button1.Text = '< '
    	$button1.UseVisualStyleBackColor = $True
    	$button1.add_Click($button1_Click)
    	#
    	# groupbox1
    	#
    	$groupbox1.Dock = 'Fill'
    	$groupbox1.Location = '0, 0'
    	$groupbox1.Name = 'groupbox1'
    	$groupbox1.Size = '185, 500'
    	$groupbox1.TabIndex = 0
    	$groupbox1.TabStop = $False
    	$groupbox1.Text = 'groupbox1'
    	#
    	# labelPanelTwo
    	#
    	$labelPanelTwo.AutoSize = $True
    	$labelPanelTwo.Location = '163, 212'
    	$labelPanelTwo.Name = 'labelPanelTwo'
    	$labelPanelTwo.Size = '53, 13'
    	$labelPanelTwo.TabIndex = 0
    	$labelPanelTwo.Text = 'panel two'
    	$splitcontainer1.ResumeLayout()
    	$form1.ResumeLayout()
    	#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 the form
    Call-splitcontainer_psf | Out-Null
    
    
    
    • This reply was modified 3 months, 2 weeks ago by Profile photo of Dan Potter Dan Potter.
    • This reply was modified 3 months, 2 weeks ago by Profile photo of Dan Potter Dan Potter.
  • #52561
    Profile photo of keith noble
    keith noble
    Participant

    That looks awesome thank you. I am going to have to take a look at this and see if I can restructure it to what I need!

You must be logged in to reply to this topic.