I created new form projects /Form projects /empty form
mainForm context this code
Goal of script is automatic generate items(PC) in toolsstripsplitbutton and for each item(PC) after click, replace text of label for text of selected item (pc)
For example:
Click to item 1 with text PC1 replace text of label to PC1
in my case when a click on item(pc1) every time text of label is replacet to PC3
Where is problem?
Thenk you
Code: Select all
$script:PCList = "PC1", "PC2", "PC3"
$script:RefreshToolStripButtonListOfPC = "Yes"
function listPC ($position, $value)
{
$global:value = $value
$ToolStripButtonListOfPC.DropDown.Items[$position].Add_click({ $LABEL_ShowPC.Text = $($value)} )
}
function listPC2 ($position, $value)
{
$global:value = $value
$item2 = New-Object System.Windows.Forms.ToolStripMenuItem
$item2.Text = $value
$ToolStripButtonListOfPC.DropDown.Items.Add($item2)
$sb =[scriptblock]::Create({$LABEL_ShowPC.Text = "$global:value"})
$item2.add_Click($sb)
}
$button1_Click={
$LABEL_ShowPC.Text = "NOT SET Button"
}
$ShowItem = {
if ($RefreshToolStripButtonListOfPC -like "Yes")
{
[int]$i = 1
foreach ($pc in $PCList)
{
#$ToolStripButtonListOfPC.DropDown.Items.Add("&$pc")
listPC2 -position $i -value $pc
$i++
}
$script:RefreshToolStripButtonListOfPC = "No"
}
}
$ladaToolStripMenuItem_Click={
$LABEL_ShowPC.Text = "FIX_PC"
}