I am new to Powershell. I am trying to create picture box that will load a lot of images in a folder. I have a folder that contain 10 images. but i want my picturebox to display it dynamically every second or 3 seconds
here is my code so far.
####################################### Form settings ##############################################
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$Form = New-Object System.Windows.Forms.Form
$Form.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$Form.Anchor = "Top,Bottom,Left,Right"
$Form.Size = New-Object System.Drawing.Size(1920,1600)
$Form.AutoScale = $True
$Form.StartPosition = "CenterScreen" #loads the window in the center of the screen
$Form.BackgroundImageLayout = "Zoom"
$Form.MinimizeBox = $True
$Form.MaximizeBox = $False
$Form.WindowState = "Normal"
$Form.SizeGripStyle = "Auto"
$Form.AutoSizeMode = New-Object System.Windows.Forms.AutoSizeMode
$Form.SizeGripStyle = "Show"
$Form.BackColor = "LightGray"
###################################################################################################
###################################################################################################
######################################### Image Folder ############################################
$ImagePreview = New-Object System.Windows.Forms.PictureBox
$ImagePreview.SizeMode = [System.Windows.Forms.PictureBoxSizeMode]::StretchImage
$ImagePreview.Location = New-Object System.Drawing.Size(965,110)
$ImagePreview.Size = New-Object System.Drawing.Size(295,370)
$ImagePreview.BackColor = "White"
$Form.Controls.Add($ImagePreview)
Function ImageFolder($ImagePreview)
{
$ImageItem = Get-Item "C:\Newfolder"
$ImagePreview.ImageLocation = $ImageItem
}
$TimerImageFolder = New-Object System.Windows.Forms.Timer
$TimerImageFolder.Interval = 3000
$TimerImageFolder.Add_Tick({$ImageFolder $ImagePreview})
$TimerImageFolder.Enabled = $True
$ImageGroupBox = New-Object System.Windows.Forms.GroupBox
$ImageGroupBox.Location = New-Object System.Drawing.Size(940,70)
$ImageGroupBox.size = New-Object System.Drawing.Size(350,440)
$ImageGroupBox.text = "Preview"
$ImageGroupBox.BackColor = "DimGray"
$ImageGroupBox.ForeColor = "White"
$Form.Controls.Add($ImageGroupBox)
####################################### Result ##############################################
$Form.Add_Shown({$Form.Activate()})
[void] $Form.ShowDialog()
I don't know which part is wrong. Thank You so much for the help Guys