Getting Dropdownbox/Combobox to align in PowerShell GUI

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
	$FormObject.Controls.Add($DropdownBox)
#	$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 
$FolderShares.Controls.Add($DropDownBox)

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

Any ideas anyone?

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

Hah hah, thanks :slight_smile:
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.