0

我想知道如何启动工作并对我的 GUI 产生明显的影响?例如,我等待一个进程的结束,这里是“mspaint”,然后我开始一项工作,每秒将我的图像从 20px 移动。当我做“ get-job”时,我已经完成了状态,但我的图像不动。

[void][reflection.assembly]::LoadWithPartialName("System.Windows.Forms")
$Image = [system.drawing.image]::FromFile("$PSScriptRoot\11.png") 
$Image1 = [system.drawing.image]::FromFile("$PSScriptRoot\10.png") 

function CreateForm {

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing

$form = New-Object System.Windows.Forms.Form 
$form.Text = " - test - "
$form.Size = New-Object System.Drawing.Size(500,400)
$form.StartPosition = "CenterScreen"
$Form.WindowState = "Normal"
$Form.ShowInTaskbar = $False
$form.ControlBox = $True
$form.Topmost = $True
$Form.MinimizeBox = $False
$Form.MaximizeBox = $False
$Form.AutoSize = $False
$Form.WindowState = "Normal"
$Form.Opacity = 1
$Form.BackgroundImage = $Image


$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,10) 
$label.Size = New-Object System.Drawing.Size(20,20) 
$label.Image = $image1;
$Label.ForeColor = "white"
$Label.BackColor = "Transparent"
$Font = New-Object System.Drawing.Font("Microsoft Sans Serif",14,[System.Drawing.FontStyle]::bold)
$Label.Font = $Font
$form.Controls.Add($label)

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(20,20)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.Font = New-Object System.Drawing.Font("Microsoft Sans Serif",10,[System.Drawing.FontStyle]::bold)
$OKButton.Width="156"
$OKButton.Height="40"
$Form.Controls.Add($OKButton)
$OKButton.Add_Click({


$job = Start-Job -name "Process" {
$label.Location = New-Object System.Drawing.Point(40,10) 
$Form.refresh
Start-Sleep -s 1
$label.Location = New-Object System.Drawing.Point(60,10) 
$Form.refresh
Start-Sleep -s 1
$label.Location = New-Object System.Drawing.Point(20,10) 
$Form.refresh
}


Do
{
Write-Host "Processes exist"
$proc = Get-Process
start-sleep 1
} While ($proc.name -contains "mspaint")
Write-Host "Processes not exist"
})

$form.ShowDialog()| Out-Null

}

CreateForm

你有什么想法吗?此致

4

0 回答 0