Dynamically generated Textboxes don't load as Variables
Posted: Thu Aug 15, 2019 11:37 pm
Product: PowerShell Studio 2019 (64 Bit)
Build: v5.6.167
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18362.0
Hi
I am dynamically generating an Options page from XML. My code is as follows:
$OptionsForPage | ForEach-Object {
$label = New-Object System.Windows.Forms.Label
$label.Name = "lbl_$($psitem.Name)"
$label.Text = $psitem.Name
$label.Location = "20, $yControl"
$label.Size = "220,20"
$label.TextAlign = 'MiddleRight'
$panel_ConfigXML.Controls.Add($label)
$TextBox = New-Object System.Windows.Forms.TextBox
$TextBox.Name = "txt_$($psitem.Name)"
$TextBox.Text = $psitem.Value
$TextBox.Location = "250, $yControl"
$TextBox.Size = "750,20"
$TextBox.TextAlign = 'Left'
$panel_ConfigXML.Controls.Add($TextBox)
$y = $y + 40
$yControl = [System.Convert]::ToString($y)
}
Everything loads and displays correctly and as expected. What is not happening, is I am expecting to be able to reference my Textbox by, for example $txt_MyTextBox, in the same way I would a static control. However, these variables (matching the name of the control) are not appearing in the same way they would with a static control.
Is there anything I need to add/change? Is this expected behavior?
Build: v5.6.167
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.18362.0
Hi
I am dynamically generating an Options page from XML. My code is as follows:
$OptionsForPage | ForEach-Object {
$label = New-Object System.Windows.Forms.Label
$label.Name = "lbl_$($psitem.Name)"
$label.Text = $psitem.Name
$label.Location = "20, $yControl"
$label.Size = "220,20"
$label.TextAlign = 'MiddleRight'
$panel_ConfigXML.Controls.Add($label)
$TextBox = New-Object System.Windows.Forms.TextBox
$TextBox.Name = "txt_$($psitem.Name)"
$TextBox.Text = $psitem.Value
$TextBox.Location = "250, $yControl"
$TextBox.Size = "750,20"
$TextBox.TextAlign = 'Left'
$panel_ConfigXML.Controls.Add($TextBox)
$y = $y + 40
$yControl = [System.Convert]::ToString($y)
}
Everything loads and displays correctly and as expected. What is not happening, is I am expecting to be able to reference my Textbox by, for example $txt_MyTextBox, in the same way I would a static control. However, these variables (matching the name of the control) are not appearing in the same way they would with a static control.
Is there anything I need to add/change? Is this expected behavior?