I am trying to create a function which will return various form objects. eg Label. However I am not able to achieve the same.
My code looks like this:
function add_label([String]$label_text, [Int]$label_location_x, [Int]$label_location_y, [Int]$lable_size) {
$label = New-Object System.Windows.Forms.Label
$label.AutoSize = $true
$label.Location = New-Object System.Drawing.Point($label_location_x,$label_location_y)
$label.Size = New-Object System.Drawing.Size($lable_size,20)
$label.Text = $label_text
$label
}
$label_product = add_label("Product: ", $label_product_location, 20, $LableSize)
$GroupBoxSetting.Controls.Add($label_product)
It does not throw any error, however the label is not displayed. Instead "product: 30 20 50" is displayed in the GUI instead of $groupBoxSetting Text.
I was wondering, is there any way to create a function, which returns the Forms object, so that we do not have to write the same code block again and again for each Forms object.
function(x, y, z)syntax. Instead it should look like this:add_label -label_text "Product: " -label_location_x $label_product_location -label_location_y 20 -lable_size $LableSize$params = @{ 'label_text'='hello'; 'label_location_x'=50; 'label_location_y'=50; 'lable_size'=10; }add_label @paramsMay not look clean in the comments because I don't know how to post multi-line code comments. You can find out more about splatting here