Getting Dropdownbox/Combobox to align in PowerShell GUI

Welcome Forums General PowerShell Q&A Getting Dropdownbox/Combobox to align in PowerShell GUI

This topic contains 2 replies, has 2 voices, and was last updated by

11 months, 1 week ago.

  • Author
  • #102811

    Topics: 3
    Replies: 6
    Points: -6
    Rank: Member

    I am writing a GUI for our helpdesk, and everything is mostly great.
    However, my dropdown boxes refuse to move left regardless of where I well them to go.
    The function I wrote to create dropdown boxes:

    Function Add-DropdownBox($DropdownBox,$DropDownHeight,$DropdownBoxLeft,$DropdownBoxTop,$DropdownBoxWidth,$DropdownBoxHeight,$FormObject)
    	$DropdownBox				= New-Object System.Windows.Forms.ComboBox
    	$DropdownBox.Location		= New-Object System.Drawing.point($DropdownBoxLeft,$DropdownBoxTop)
    	$DropdownBox.Size			= New-Object System.Drawing.Size($DropdownBoxWidth,$DropdownBoxHeight)
    	$DropDownBox.DropDownHeight = $DropDownHeight
    #	$DropdownBox

    The command I use to create them in the script:

    $FolderShareDropdown1 = Add-DropdownBox -DropdownBox $FolderShareDropdown1 -DropDownHeight 200 $DropdownBoxLeft $CheckBoxAlignCol1 -DropdownBoxTop ($CheckBoxAlignRow+($TextboxHeight*1)) -DropdownBoxWidth ($TextBoxWidth*1.9) -DropdownBoxHeight $Textboxheight -FormObject $FolderShares

    This is all on one line in my script.

    Everything other than the leftmost position works fine, i.e. height changes, width changes and so on, when I change the variables. Just not the left most position.
    Other elements position themselves correctly based on the $CheckBoxAlignCol1 variable (TextBoxes/Checkboxes/Buttons), so the variable does "work".
    If I write out the full lines, for example:

    $DropDownBox = New-Object System.Windows.Forms.ComboBox
    $DropDownBox.Location = New-Object System.Drawing.Size(200,50) 
    $DropDownBox.Size = New-Object System.Drawing.Size(10,20) 
    $DropDownBox.DropDownHeight = 200 

    Then the dropdown box is positioned correctly, so I really can't see why the function doesn't work.

    Any ideas anyone?

  • #102812

    Topics: 8
    Replies: 1190
    Points: 639
    Helping Hand
    Rank: Major Contributor

    Look at your command:

    ... -DropDownHeight 200 $DropdownBoxLeft $CheckBoxAlignCol1 ...

    Should be -DropDownBoxLeft. Another recommendation is to use splatting to make things much cleaner and easier to read:

    $params = @{
        DropdownBox       = $FolderShareDropdown1 
        DropDownHeight    = 200 
        DropdownBoxLeft   = $CheckBoxAlignCol1
        DropdownBoxTop    = ($CheckBoxAlignRow+($TextboxHeight*1)) 
        DropdownBoxWidth  = ($TextBoxWidth*1.9) 
        DropdownBoxHeight = $Textboxheight 
        FormObject        = $FolderShares
    $FolderShareDropdown1 = Add-DropdownBox @params
    • #102818

      Topics: 3
      Replies: 6
      Points: -6
      Rank: Member

      Hah hah, thanks 🙂
      I must have stared myself blind at my code so I couldn't see something that obvious.

      I use splatting in lots of places, but I can't see any value in using it here, since I might as well just put the needed lines into my code, which would take less space.

The topic ‘Getting Dropdownbox/Combobox to align in PowerShell GUI’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort