我是Powershell的新手,并且遇到了这个问题。我有一个非常长的自动化安装脚本,通过MySQL安装/帐户设置和其他.msi的运行。在Powershell中导入一个动画的.gif到Windows.Forms
当用户等待脚本完成时,我有这个“Please Wait”提示画面,其中包含图片框中的旋转风轮.gif。
问题是,如果我将form.visible设置为$ true并且稍后在脚本中关闭它,那么.gif本身不会移动。它显示但失去了它的动画。如果我将form.visible更改为“false”,并通过添加form.showdialog()参数将窗体更改为模式,则动画在.gif中是完美的,但脚本会暂停并且只能在关闭窗口后才能进行。有没有一种方法可以让脚本在不丢失.gif中的动画的情况下进展?请帮忙。由于某种原因,我发现Powershell和.gif的论坛很少。这是表单的代码。
$Form = New-Object system.Windows.Forms.Form
$Form.Location= New-Object System.Drawing.Size(100,100)
$Form.Size= New-Object System.Drawing.Size(550,170)
$Form.StartPosition = "Manual"
$Form.Visible=$true
$Form.Enabled = $true
[reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$file = (get-item 'PathToMyGifFile')
$img = [System.Drawing.Image]::Fromfile($file);
[System.Windows.Forms.Application]::EnableVisualStyles();
$pictureBox = new-object Windows.Forms.PictureBox
$pictureBox.Location = New-Object System.Drawing.Size(0,1)
$pictureBox.Size = New-Object System.Drawing.Size(100,80)
$pictureBox.Image = $img
$Form.controls.add($pictureBox)
$Label1 = New-Object System.Windows.Forms.Label
$Label1.Text = "Please wait for Installation to complete"
$Label1.Location= New-Object System.Drawing.Size(110,35)
$Label1.Size = New-Object System.Drawing.Size(400,25)
$Label1Font = New-Object System.Drawing.Font("Tahoma",10,
[System.Drawing.FontStyle]::Bold)
$Label1.Font = $Label1Font
$Label1.BackColor = "white"
$Form.Controls.Add($Label1)
$Label2 = New-Object System.Windows.Forms.Label
$Label2.Text = "This may take several minutes . . ."
$Label2.Location= New-Object System.Drawing.Size(120,60)
$Label2.Size = New-Object System.Drawing.Size(370,75)
$Label2Font = New-Object System.Drawing.Font("Tahoma",10,
[System.Drawing.FontStyle]::Regular)
$Label2.Font = $Label2Font
$Label2.BackColor = "white"
$Form.Controls.Add($Label2)
$BackDrop = New-Object System.Windows.Forms.Label
$BackDrop.Location = New-Object System.Drawing.Size(0,0)
$BackDrop.Size = New-Object System.Drawing.Size(550,150)
$BackDrop.BorderStyle = [System.Windows.Forms.BorderStyle]::FixedSingle;
$BackDrop.BackColor = [System.Drawing.Color]::White
$Form.Controls.Add($WaitBackGroundBox)
$Form.Topmost = $True
[void] $Form.ShowDialog() # If absent, animation is lost. If present
# (combined with form.visible = $false), script
# halts until the form itself is closed.
嗯,令人惊讶的控制没有来了,当我正在研究的指标。这很漂亮。如果我无法使用.gif修复表单,那么这不是一个糟糕的解决方法。谢谢! –