在我的Powershell GUI中,我有两种模式:连接和解除连接。每个步骤都有一个步骤列表。该列表从xml中读取,然后加载到流程布局面板中,作为每个步骤的标签。因此,如果我有8个连接步骤,我将在流程布局面板中创建8个标签。
我希望在模式更改时动态更改标签。如果我处于连接模式并转到断开连接模式,我需要从函数运行空间加载流程布局面板中的相关步骤
在我的脚本中,我有三个运行空间(一个用于GUI,一个用于函数,另一个用于计时器)。
在Gui运行空间中,PanelLabelInner(流程布局面板)被包装成PanelLabel Outer。这是用于垂直居中。我需要将标签添加到PanelLabelInner中。
我需要完成BUiltXML函数。首先,在模式更改时删除所有标签,然后更新ui以显示新标签:我该怎么做?
对于这段代码,没有添加任何内容,我想我必须使用更新、刷新。。。
桂运行空间:
$CommonHashTable.PanelLabelOuter=New-Object System.Windows.Forms.Panel
$CommonHashTable.PanelLabelOuter.BackColor = [string]$PanelLabelOuterCfg.BackColor
$CommonHashTable.PanelLabelOuter.Name ="PanelLabelOuter"
$CommonHashTable.PanelLabelOuter.BorderStyle =[string]$PanelLabelOuterCfg.BorderStyle
$CommonHashTable.PanelLabelOuter.Dock = "Fill"
$CommonHashTable.PanelLabelOuter.AutoSize = $false
$CommonHashTable.MiddleLayout.Controls.Add($CommonHashTable.PanelLabelOuter,2,0)
$CommonHashTable.PanelLabelInner=New-Object System.Windows.Forms.FlowLayoutPanel
$CommonHashTable.PanelLabelInner.AutoSize = $false
$CommonHashTable.PanelLabelInner.Height = $CommonHashTable.c*20
$CommonHashTable.PanelLabelInner.Left = [Int32]$PanelLabelInnerCfg.Left
$CommonHashTable.PanelLabelInner.Width= $CommonHashTable.PanelLabelOuter.Width
$top=[int32](($CommonHashTable.PanelLabelOuter.Size.Height - $CommonHashTable.PanelLabelInner.Size.Height) / 2)
$CommonHashTable.PanelLabelInner.Top=$top
$CommonHashTable.PanelLabelInner.Padding= 0
$CommonHashTable.PanelLabelInner.Anchor = 'None'
$CommonHashTable.PanelLabelInner.FlowDirection = "TopDown"
$CommonHashTable.PanelLabelInner.WrapContents = $false
$CommonHashTable.PanelLabelInner.BackColor = [string]$PanelLabelInnerCfg.BackColor
$CommonHashTable.PanelLabelInner.Name ="PanelLabelInner"
$CommonHashTable.PanelLabelOuter.Controls.Add($CommonHashTable.PanelLabelInner)
功能运行空间
function BuiltXML{
Switch ($CommonHashTable.Phase) {
{$CommonHashTable.Phase -eq "Connect"}
{
$ConnectLabelText = "Connection"
$CommonHashTable.sourceXML = [xml](Get-Content $ProductPathXmlConnectionLabels.xml)
}
{$CommonHashTable.Phase -eq "Disconnect"}
{
$ConnectLabelText = "Logout"
$CommonHashTable.sourceXML = [xml](Get-Content $ProductPathXmlDeconnectionLabels.xml)
}
}
$CommonHashTable.steps= $CommonHashTable.sourceXML.Dialer.Steps.Stp
$CommonHashTable.c = $CommonHashTable.steps.count
$CommonHashTable.PanelLabelInner.Invoke([Action[string]] {
$i =1
#$CommonHashTable.PanelLabelInner.Controls.Remove($CommonHashTable.Lbl)
$CommonHashTable.Lbl.Controls.Clear()
foreach ($e in $CommonHashTable.steps)
{
$CommonHashTable.Lbl = New-Object System.Windows.Forms.Label
$CommonHashTable.Lbl.Size=New-Object System.Drawing.Size($CommonHashTable.PanelLabelInner.Size.Width,20)
$CommonHashTable.Lbl.AutoSize = $false
$CommonHashTable.Lbl.Name = "Label"+$i
$CommonHashTable.Lbl.TextAlign = "MiddleLeft"
$CommonHashTable.Lbl.Text = $e.Label
$CommonHashTable.PanelLabelInner.Controls.Add($CommonHashTable.Lbl)
$i++
}
},
'normal')
}
我找到了一个解决方案。。。该函数还构建了与标签数量相关的流程布局面板。所以我有一个高度很好的流程布局面板。我只需要在需要切换时清除外部面板,添加这些标签,然后进行更新。
function BuiltXML{
Switch ($CommonHashTable.Phase) {
{$CommonHashTable.Phase -eq "Connect"}
{
$CommonHashTable.ConnectLabel.Text = "Connexion"
$sourceXML = [xml](Get-Content $ProductPathXmlConnectionLabels.xml)
}
{$CommonHashTable.Phase -eq "Disconnect"}
{
$CommonHashTable.ConnectLabel.Text = "Deconnexion"
$sourceXML = [xml](Get-Content $ProductPathXmlDeconnectionLabels.xml)
}
}
$etapes = $sourceXML.Dialer.Etapes.Etape
$c = $etapes.count
$CommonHashTable.PanelLabelOuter.Invoke(
[Action] {
$CommonHashTable.PanelLabelOuter.Controls.Clear()
$CommonHashTable.PanelLabelInner=New-Object System.Windows.Forms.FlowLayoutPanel
$CommonHashTable.PanelLabelInner.AutoSize = $false
$CommonHashTable.PanelLabelInner.Height = $c*20
$CommonHashTable.PanelLabelInner.Left = [Int32]$PanelLabelInnerCfg.Left
$CommonHashTable.PanelLabelInner.Width= $CommonHashTable.PanelLabelOuter.Width
$top=[int32](($CommonHashTable.PanelLabelOuter.Size.Height - $CommonHashTable.PanelLabelInner.Size.Height) / 2)
$CommonHashTable.PanelLabelInner.Top=$top
$CommonHashTable.PanelLabelInner.Padding= 0
$CommonHashTable.PanelLabelInner.Anchor = 'None'
$CommonHashTable.PanelLabelInner.FlowDirection = "TopDown"
$CommonHashTable.PanelLabelInner.WrapContents = $false
$CommonHashTable.PanelLabelInner.BackColor = [string]$PanelLabelInnerCfg.BackColor
$CommonHashTable.PanelLabelInner.Name ="PanelLabelInner"
$CommonHashTable.PanelLabelOuter.Controls.Add($CommonHashTable.PanelLabelInner)
$i =1
foreach ($e in $etapes)
{
$CommonHashTable.Lbl = New-Object System.Windows.Forms.Label
$CommonHashTable.Lbl.Size=New-Object System.Drawing.Size($CommonHashTable.PanelLabelInner.Size.Width,20)
$CommonHashTable.Lbl.AutoSize = $false
$CommonHashTable.Lbl.Name = "Label"+$i
$CommonHashTable.Lbl.TextAlign = "MiddleLeft"
#$CommonHashTable.Lbl.Font = New-Object System.Drawing.Font([string]$lblCfg.Font,[int32]$lblCfg.Size,[System.Drawing.FontStyle]::[string]$lblCfg.Style)
#$CommonHashTable.Lbl.ForeColor = [string]$lblCfg.Color
$CommonHashTable.Lbl.Text = $e.Label
$CommonHashTable.PanelLabelInner.Controls.Add($CommonHashTable.Lbl)
$i++
}
$CommonHashTable.PanelLabelInner.update()
}
)
}