PictureBox在后台?

时间:2015-08-12 10:14:07

标签: winforms powershell background gif

我希望在我使用PowerShell创建的表单中显示GIF作为背景。

我已经知道如何显示GIF并且效果很好,但当然我的所有按钮和文本框等都会消失。

1 个答案:

答案 0 :(得分:1)

背景图片通过表格的BackgroundImage属性分配:

Add-Type -Assembly System.Windows.Forms

$form = New-Object Windows.Forms.Form

$img = [Drawing.Image]::FromFile('C:\path\to\your.gif')
$form.BackgroundImage = $img
$form.BackgroundImageLayout = 'Tile'

$form.ShowDialog()

有关在PowerShell中使用表单的详细信息,请参阅here

为了显示动画 GIF(你应该在你的问题中提到过),PictureBox元素似乎是required。您可以通过在其他元素之后添加它(新元素放在现有元素后面/下面)来获取其他元素:

$img = [Drawing.Image]::FromFile('C:\path\to\your.gif')

$picbox = New-Object Windows.Forms.PictureBox
$picbox.Width  = $img.Size.Width
$picbox.Height = $img.Size.Height
$picbox.Image  = $img

$form.Controls.Add($otherElement)
$form.Controls.Add($yetAnotherElement)
$form.Controls.Add($picbox)

或通过SendToBack()方法将其发送到后面:

$img = [Drawing.Image]::FromFile('C:\path\to\your.gif')

$picbox = New-Object Windows.Forms.PictureBox
$picbox.Width  = $img.Size.Width
$picbox.Height = $img.Size.Height
$picbox.Image  = $img

$form.Controls.Add($picbox)
$form.Controls.Add($otherElement)
$form.Controls.Add($yetAnotherElement)

$picbox.SendToBack()