我是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修復表單,那麼這不是一個糟糕的解決方法。謝謝! –