在我的Powershell GUI中,我有两种模式:连接和断开连接。每个都有一个步骤列表。此列表从xml中读取,然后加载到flowlayout面板中,作为每个步骤的标签。因此,如果我有8个连接步骤,我将在flowlayout面板中创建8个标签。
我希望在模式更改时动态更改标签。如果我处于连接模式并转到解除连接模式,我需要从函数运行空间加载flowlayout面板中的相关步骤
在我的脚本中,我有三个运行空间(一个用于GUI,一个用于功能,一个用于计时器)。
在Gui运行空间中,PanelLabelInner(flowlayoutpanel)被包装到PanelLabelOuter中。这是垂直居中。我需要将标签添加到PanelLabelInner中。
我需要完成BUiltXML功能。首先,在模式更改时删除所有标签,然后更新ui以显示新标签:我该怎么做?
使用此代码,没有添加任何东西,我想我必须使用像update,refresh ...
这样的东西Gui runspace:
$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 $ProductPath\Xml\ConnectionLabels.xml)
}
{$CommonHashTable.Phase -eq "Disconnect"}
{
$ConnectLabelText = "Logout"
$CommonHashTable.sourceXML = [xml](Get-Content $ProductPath\Xml\DeconnectionLabels.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')
}
答案 0 :(得分:0)
我找到了一个解决方案......该功能还根据标签数量构建了flowlayout面板。所以我有一个高度良好的flowlayout面板。我只需要在需要切换时添加外部面板,添加这些标签然后进行更新。
function BuiltXML{
Switch ($CommonHashTable.Phase) {
{$CommonHashTable.Phase -eq "Connect"}
{
$CommonHashTable.ConnectLabel.Text = "Connexion"
$sourceXML = [xml](Get-Content $ProductPath\Xml\ConnectionLabels.xml)
}
{$CommonHashTable.Phase -eq "Disconnect"}
{
$CommonHashTable.ConnectLabel.Text = "Deconnexion"
$sourceXML = [xml](Get-Content $ProductPath\Xml\DeconnectionLabels.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()
}
)
}