I have created a splash screen for the GUI I am working on and I cannot get the Splash Screen to disappear after 3 seconds.
Here is the code:
<#
Program:Personal Information Manager v2.0
FileName:imu.ps1
Author:Larry Moore
Copyright:2013 Avdiel Data Solutions
Synopsis:Provides data management service for the following:
Address Book - AddressBook.dat
Check Book - CheckBook.dat
Mileage Log - MileageLog.dat
Calendar - Calendar.dat
Publication Date:25 April 2013
Editor:PowerShell ISE v3.0
#>
<#
Load Assemblies
#>
[Reflection.Assembly]::LoadWithPartialName("System") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("mscorlib") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.Data") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("System.IO") | Out-Null
[Reflection.Assembly]::LoadWithPartialName("Microsoft.VisualBasic") | Out-Null
[reflection.assembly]::LoadWithPartialName("System.DirectoryServices") | Out-Null
#Example: [System.Windows.Forms.MessageBox]::Show($MSG , $TITLE, $Type, $Icon)
<#
Create Splash Screen
#>
function Create-Splash
{
# Form Objects
$script:frmSplash = New-Object System.Windows.Forms.Form
$lblSplashLoad = New-Object System.Windows.Forms.Label
$lblSplashOwner = New-Object System.Windows.Forms.Label
$lblSplashTitle = New-Object System.Windows.Forms.Label
$pbxSplash = New-Object System.Windows.Forms.PictureBox
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
# Form Code
$frmSplash.BackColor = [System.Drawing.Color]::FromArgb(255,255,255,255)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 262
$System_Drawing_Size.Width = 284
$frmSplash.ClientSize = $System_Drawing_Size
$frmSplash.DataBindings.DefaultDataSourceUpdateMode = 0
$frmSplash.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon('C:\PowerShell\Resources\Images\EyeOfGod.ico')
$frmSplash.Name = "frmSplash"
$frmSplash.StartPosition = 1
$frmSplash.Text = "Splash Screen"
# Load Label Code
$lblSplashLoad.AutoSize = $True
$lblSplashLoad.DataBindings.DefaultDataSourceUpdateMode = 0
$lblSplashLoad.Font = New-Object System.Drawing.Font("Courier New",15.75,3,3,0)
$lblSplashLoad.ForeColor = [System.Drawing.Color]::FromArgb(255,0,0,192)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 12
$System_Drawing_Point.Y = 230
$lblSplashLoad.Location = $System_Drawing_Point
$lblSplashLoad.Name = "lblSplashLoad"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 231
$lblSplashLoad.Size = $System_Drawing_Size
$lblSplashLoad.TabIndex = 3
$lblSplashLoad.Text = "Initializing...."
$lblSplashLoad.TextAlign = 16
$frmSplash.Controls.Add($lblSplashLoad)
# Owner Label Code
$lblSplashOwner.AutoSize = $True
$lblSplashOwner.DataBindings.DefaultDataSourceUpdateMode = 0
$lblSplashOwner.Font = New-Object System.Drawing.Font("Courier New",8.25,0,3,0)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 51
$System_Drawing_Point.Y = 204
$lblSplashOwner.Location = $System_Drawing_Point
$lblSplashOwner.Name = "lblSplashOwner"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 14
$System_Drawing_Size.Width = 189
$lblSplashOwner.Size = $System_Drawing_Size
$lblSplashOwner.TabIndex = 2
$lblSplashOwner.Text = "2013 Avdiel Data Solutions"
$lblSplashOwner.TextAlign = 16
$frmSplash.Controls.Add($lblSplashOwner)
# Label Title Code
$lblSplashTitle.AutoSize = $True
$lblSplashTitle.DataBindings.DefaultDataSourceUpdateMode = 0
$lblSplashTitle.Font = New-Object System.Drawing.Font("Kunstler Script",20.25,1,3,0)
$lblSplashTitle.ForeColor = [System.Drawing.Color]::FromArgb(255,64,0,64)
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 175
$lblSplashTitle.Location = $System_Drawing_Point
$lblSplashTitle.Name = "lblSplashTitle"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 29
$System_Drawing_Size.Width = 272
$lblSplashTitle.Size = $System_Drawing_Size
$lblSplashTitle.TabIndex = 1
$lblSplashTitle.Text = "Personal Information Manager"
$lblSplashTitle.TextAlign = 16
$frmSplash.Controls.Add($lblSplashTitle)
# Picturebox Code
$pbxSplash.DataBindings.DefaultDataSourceUpdateMode = 0
$pbxSplash.Dock = 1
$pbxSplash.Image = [System.Drawing.Image]::FromFile('C:\PowerShell\Resources\Images\PIMLogo.bmp')
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 0
$System_Drawing_Point.Y = 0
$pbxSplash.Location = $System_Drawing_Point
$pbxSplash.Name = "pbxSplash"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 172
$System_Drawing_Size.Width = 284
$pbxSplash.Size = $System_Drawing_Size
$pbxSplash.SizeMode = 1
$pbxSplash.TabIndex = 0
$pbxSplash.TabStop = $False
$frmSplash.Controls.Add($pbxSplash)
#Save the initial state of the form
$InitialFormWindowState = $frmSplash.WindowState
#Init the OnLoad event to correct the initial state of the form
$frmSplash.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$frmSplash.ShowDialog()| Out-Null
} #End Function
Create-Splash
Start-Sleep -seconds 3
$frmSplash.Close()