locked
Any way to make checkboxes appear like text in a book as in left to right? RRS feed

  • Question

  • Is there any way to make my checkboxes appear left to right instead of top to bottom and repeating?

    I want it to read A B C....etc on the first row. Maybe this is not possible with checkboxListview? If not what would I use?  Thanks!

    function Popup_Final {
    	#----------------------------------------------
    	# Import the Assemblies
    	#----------------------------------------------
    	[void][reflection.assembly]::Load('System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089')
    	[void][reflection.assembly]::Load('System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
    	#endregion Import Assemblies
    	#----------------------------------------------
    	# Form Objects
    	#----------------------------------------------
    	[System.Windows.Forms.Application]::EnableVisualStyles()
    	$formDriveTroubleshooter = New-Object 'System.Windows.Forms.Form'
    	$tablelayoutpanel1 = New-Object 'System.Windows.Forms.TableLayoutPanel'
    	$checkboxlistGroup = New-Object 'System.Windows.Forms.GroupBox'
    	$listboxCheckedDrives = New-Object 'System.Windows.Forms.checkedListbox'
            $buttonGenerateReport = New-Object 'System.Windows.Forms.Button'
            $listboxReport = New-Object 'System.Windows.Forms.Listbox'	
    	$initialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    	# End Form Objects
    	#----------------------------------------------
    	# Region Control Helper Functions
        #----------------------------------------------
        #
        function Report() { 
        param( $String )
         $listboxReport.Items.Add("$String")
        }
        #
        # variables for form generation
        #
        function CheckedDrives(){
            $listboxCheckedDrives.checkedItems -join ','
            $checkedDrives = $listboxCheckedDrives.Items | ?{$listboxCheckedDrives.checkedItems -contains $_ }
            if (!($checkedDrives)) { 
                $checkedDrives='No drives were selected.'
            }else{ }
            Report "$checkedDrives"
        }
        # button actions
        #
    	$buttonGenerateReport_Click={
            $listboxReport.Items.Clear()
            CheckedDrives
            if (!$listboxReport.Items) {   
            }else {
                ([System.Windows.Forms.Clipboard]::SetText($listboxReport.Items))
    	    }
        }
    
    	# endregion Generated Events
    	#----------------------------------------------
    	# Region Form Code
    	#----------------------------------------------
    	$formDriveTroubleshooter.SuspendLayout()
    	$tablelayoutpanel1.SuspendLayout()
    	$checkboxlistGroup.SuspendLayout()
    	#
    	# formDriveTroubleshooter
    	#
    	$formDriveTroubleshooter.Controls.Add($tablelayoutpanel1)
    	$formDriveTroubleshooter.AutoScaleDimensions = '6, 13'
    	$formDriveTroubleshooter.AutoScaleMode = 'Font'
    	$formDriveTroubleshooter.BackColor = 'Control'
        $formDriveTroubleshooter.AutoSize = $True
    	$formDriveTroubleshooter.FormBorderStyle = 'FixedDialog'
    	$formDriveTroubleshooter.MaximizeBox = $False
    	$formDriveTroubleshooter.MinimizeBox = $False
    	$formDriveTroubleshooter.Name = 'formDriveTroubleshooter'
    	$formDriveTroubleshooter.StartPosition = 'CenterScreen'
    	$formDriveTroubleshooter.Text = 'Drive Troubleshooter'
    	#
    	# tablelayoutpanel1
    	#
    	$tablelayoutpanel1.Controls.Add($checkboxlistGroup, 0, 1)
    	$tablelayoutpanel1.Controls.Add($buttonGenerateReport, 0, 2)
    	$tablelayoutpanel1.Controls.Add($listboxReport, 0, 3)
    	$tablelayoutpanel1.AutoSize = $True
    	$tablelayoutpanel1.AutoSizeMode = 'GrowOnly'
    	$tablelayoutpanel1.ColumnCount = 3
    	$system_Windows_Forms_ColumnStyle_1 = New-Object 'System.Windows.Forms.ColumnStyle'
    	[void]$tablelayoutpanel1.ColumnStyles.Add($system_Windows_Forms_ColumnStyle_1)
    	$system_Windows_Forms_ColumnStyle_2 = New-Object 'System.Windows.Forms.ColumnStyle'
    	[void]$tablelayoutpanel1.ColumnStyles.Add($system_Windows_Forms_ColumnStyle_2)
    	$system_Windows_Forms_ColumnStyle_3 = New-Object 'System.Windows.Forms.ColumnStyle'
    	[void]$tablelayoutpanel1.ColumnStyles.Add($system_Windows_Forms_ColumnStyle_3)
    	$tablelayoutpanel1.Dock = 'Fill'
    	$tablelayoutpanel1.Location = '0, 0'
    	$tablelayoutpanel1.Name = 'tablelayoutpanel1'
    	$tablelayoutpanel1.RowCount = 5
    	$system_Windows_Forms_RowStyle_4 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_4)
    	$system_Windows_Forms_RowStyle_5 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_5)
    	$system_Windows_Forms_RowStyle_6 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_6)
    	$system_Windows_Forms_RowStyle_7 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_7)
    	$system_Windows_Forms_RowStyle_8 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_8)
    	$system_Windows_Forms_RowStyle_9 = New-Object 'System.Windows.Forms.RowStyle'
    	[void]$tablelayoutpanel1.RowStyles.Add($system_Windows_Forms_RowStyle_9)
    	$tablelayoutpanel1.Size = '469, 554'
    	$tablelayoutpanel1.TabIndex = 3
    	$tablelayoutpanel1.add_Paint($tablelayoutpanel1_Paint)
        #
    	# checkboxlistGroup
    	#
    	$checkboxlistGroup.Controls.Add($listboxCheckedDrives)
    	$checkboxlistGroup.AutoSize = $True
    	$checkboxlistGroup.AutoSizeMode = 'GrowOnly'
    	$checkboxlistGroup.BackColor = 'Control'
    	$checkboxlistGroup.BackgroundImageLayout = 'None'
    	$tablelayoutpanel1.SetColumnSpan($checkboxlistGroup, 3)
    	$checkboxlistGroup.Dock = 'Top'
    	$checkboxlistGroup.Font = 'Microsoft Sans Serif, 8.25pt'
    	$checkboxlistGroup.Location = '3, 129'
        # left, top, right, bottom
        $checkboxlistGroup.Margin = '4,0,4,0'
    	$checkboxlistGroup.Name = 'checkboxlistGroup'
    	$checkboxlistGroup.Size = '463, 49'
    	$checkboxlistGroup.TabIndex = 1
    	$checkboxlistGroup.TabStop = $False
    	$checkboxlistGroup.Text = 'Select Drives:'
    	$checkboxlistGroup.UseCompatibleTextRendering = $True
    	$checkboxlistGroup.add_Enter($checkboxlistGroup_Enter)
    	#
    	# listboxCheckedDrives
    	#
    	$listboxCheckedDrives.BackColor = 'Menu'
    	$listboxCheckedDrives.BorderStyle = 'None'
    	$listboxCheckedDrives.checkOnClick = $True
    	$listboxCheckedDrives.ColumnWidth = 30
    	$listboxCheckedDrives.Dock = 'Top'
    	$listboxCheckedDrives.FormattingEnabled = $True
     	$listboxCheckedDrives.Items.Add('A')
    	$listboxCheckedDrives.Items.Add('B')
    	$listboxCheckedDrives.Items.Add('C')
    	$listboxCheckedDrives.Items.Add('D')
    	$listboxCheckedDrives.Items.Add('E')
    	$listboxCheckedDrives.Items.Add('F')
    	$listboxCheckedDrives.Items.Add('G')
    	$listboxCheckedDrives.Items.Add('H')
    	$listboxCheckedDrives.Items.Add('I')
    	$listboxCheckedDrives.Items.Add('J')
    	$listboxCheckedDrives.Items.Add('K')
    	$listboxCheckedDrives.Items.Add('L')
    	$listboxCheckedDrives.Items.Add('M')
    	$listboxCheckedDrives.Items.Add('N')
    	$listboxCheckedDrives.Items.Add('O')
    	$listboxCheckedDrives.Items.Add('P')
    	$listboxCheckedDrives.Items.Add('Q')
    	$listboxCheckedDrives.Items.Add('R')
    	$listboxCheckedDrives.Items.Add('S')
    	$listboxCheckedDrives.Items.Add('T')
    	$listboxCheckedDrives.Items.Add('U')
    	$listboxCheckedDrives.Items.Add('V')
    	$listboxCheckedDrives.Items.Add('W')
    	$listboxCheckedDrives.Items.Add('X')
    	$listboxCheckedDrives.Items.Add('Y')
    	$listboxCheckedDrives.Items.Add('Z')
        $listboxCheckedDrives.Location = '3, 16'
        $listboxCheckedDrives.MultiColumn = $True
        $listboxCheckedDrives.Name = 'listboxCheckedDrives'
    	$listboxCheckedDrives.Size = '457, 30'
        $listboxCheckedDrives.Margin = '10,0,4,0'
    	$listboxCheckedDrives.TabIndex = 2
    	$listboxCheckedDrives.UseCompatibleTextRendering = $True
    	$listboxCheckedDrives.UseTabStops = $False
        $listboxCheckedDrives.Sorted = $True
    	$listboxCheckedDrives.add_SelectedIndexChanged($listboxCheckedDrives_SelectedIndexChanged)
    	#
    	# buttonGenerateReport
    	#
    	$buttonGenerateReport.AccessibleName = ''
    	$buttonGenerateReport.AutoSize = $True
    	$tablelayoutpanel1.SetColumnSpan($buttonGenerateReport, 3)
    	$buttonGenerateReport.Dock = 'Fill'
    	$buttonGenerateReport.Font = 'Microsoft Sans Serif, 12pt, style=Bold'
    	$buttonGenerateReport.Location = '3, 184'
    	$buttonGenerateReport.Name = 'buttonGenerateReport'
    	$buttonGenerateReport.Size = '463, 39'
    	$buttonGenerateReport.TabIndex = 3
    	$buttonGenerateReport.Text = 'Generate Report'
    	$buttonGenerateReport.UseCompatibleTextRendering = $True
    	$buttonGenerateReport.UseVisualStyleBackColor = $True
    	$buttonGenerateReport.add_Click($buttonGenerateReport_Click)
    	#
    	# listboxReport
    	#
    	$tablelayoutpanel1.SetColumnSpan($listboxReport, 3)
    	$listboxReport.FormattingEnabled = $True
    	$listboxReport.Location = '3, 229'
    	$listboxReport.Name = 'listboxReport'
    	$listboxReport.Size = '463, 251'
    	$listboxReport.TabIndex = 4
    
    	$checkboxlistGroup.ResumeLayout()
    	$tablelayoutpanel1.ResumeLayout()
    	$formDriveTroubleshooter.ResumeLayout()
    	#----------------------------------------------
    	# End Form Code
    	#----------------------------------------------
    	#Save the initial state of the form
    	$initialFormWindowState = $formDriveTroubleshooter.WindowState
    	#Init the OnLoad event to correct the initial state of the form
    	$formDriveTroubleshooter.add_Load($form_StateCorrection_Load)
    	#Clean up the control events
    	$formDriveTroubleshooter.add_FormClosed($form_Cleanup_FormClosed)
    	#Show the Form
    	return $formDriveTroubleshooter.ShowDialog()
    } #End Function
    #Call the form
    Popup_Final | Out-Null


    • Edited by BekzMix Friday, August 3, 2018 2:07 PM
    Thursday, August 2, 2018 9:15 PM

All replies

  • Set multicolumn mode to $true and make checkedlb wide enough for the number of columns you need.

    https://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.multicolumn(v=vs.110).aspx


    \_(ツ)_/

    • Proposed as answer by I.T Delinquent Friday, August 3, 2018 10:16 AM
    Thursday, August 2, 2018 9:26 PM
  •     $listboxCheckedDrives.MultiColumn = $True
        $listboxCheckedDrives.ColumnWidth = 30

    I already have this set, it makes the items appear top to bottom in column 1 then starts again column 2 top to bottom, and repeats. I want it to go left to right in 2 rows.

    Friday, August 3, 2018 2:07 PM
  • Use a FlowLayoutPanel and fill it with checkboxes.  THis will allow you to control the direction of the layout or you can just put all of the cheeks in a GroupBox.


    \_(ツ)_/

    Friday, August 3, 2018 2:33 PM