title: Importing an animated .gif into Windows.Forms in Powershell
body: <p>I'm newer to Powershell and am running into this issue. I have a very long automated install script that runs through MySQL install/account setup and other .msi's.</p>
  
  <p>While the users wait for the script to complete, I have this "Please Wait" prompt display that contains a spinning pinwheel .gif in the picturebox.</p>
  
  <p>The problem is that if I set the form.visible to $true and have it close later on in the script, then the .gif itself will not move. It displays but loses its animation. If I change the form.visible to "false" and change the form to modal with adding a form.showdialog() parameter, the animation is perfect in the .gif but the script halts and can only progress after the window is closed. Is there a way for the script to progress without losing the animation in the .gif? Please help. I've found very little forums on powershell and .gif's for some reason. Here is the code for the form.</p>
  
  <pre><code>$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.
  </code></pre>