i have a project with multiple files and hundreds of lines of code so i cannot paste everything here but I'll try to describe my issue as best I can to allow someone to help.
the GUI I'm building has a new tabpage each time you connect to a computer in the field. the tab is correctly creates and works great.
when the tab is created, I create a new variable that is used to indicate if that tab already exists, to make sure the user does not connect to the same computer twice. when he/she clicks connect, a new tab appears, where I'll build all the logic and controls i need.
anyway, in this function I'm pasting here, you can see the process, if the variable does not exists, i create a tabpage, set the variable, and if it exists, i set the focus to the existing tabpage.
my issue is that, when i need to close the tabpage, i need to remove the variable, but my function says it cannot find a variable with that name. i hope someone can understand this and helps!
thanks!
Code: Select all
function create-newTab {
[CmdletBinding()]
param (
$pcname
)
$button_click = {
$varName = ($this.Text -split ' ')[1]
Get-Variable -name $varName | Remove-Variable -Force
$tabControl1.TabPages.Remove($tabControl1.SelectedTab)
}
new-variable -Name "$pcname" -Scope global
$tabcontrol1.TabPages.Add($comboPCName.Text, $comboPCName.Text)
$button = New-Object System.Windows.Forms.Button
$button.Text = "Close $pcname"
$button.Parent = $tabcontrol1.TabPages[$pcname]
$button.Location = '794, 5'
$button.Size = '42, 23'
$button.add_Click($button_Click)
$tabcontrol1.TabPages[$pcname].Controls.Add($thisbutton)
}