Winforms 如何正确使用Powershell表单?

Winforms 如何正确使用Powershell表单?,winforms,powershell,Winforms,Powershell,最近,我开始熟悉Powershell中的windows窗体,我想创建一个带有图片的按钮。图片以马赛克样式显示在按钮上。有没有办法让图片保持在按钮的中央 这是我的密码: $Shutdown_button = New-Object System.Windows.Forms.Button $Shutdown_button.Location = New-Object System.Drawing.Size(781,115) $Shutdown_button.Size = New-Object Syst

最近,我开始熟悉Powershell中的windows窗体,我想创建一个带有图片的按钮。图片以马赛克样式显示在按钮上。有没有办法让图片保持在按钮的中央

这是我的密码:

$Shutdown_button = New-Object System.Windows.Forms.Button
$Shutdown_button.Location = New-Object System.Drawing.Size(781,115)
$Shutdown_button.Size = New-Object System.Drawing.Size(90,90)
$Shutdown_button.Text = "Shutdown"
$Shutdown_button.ForeColor = "Black"
$Shutdown_button.TextAlign = 'BottomCenter'
$Shutdown_button.ImageAlign = 'TopCenter'
$Image_Shutdown = [system.drawing.image]::FromFile("$($scriptPath)Source\Images\shutdown.png")
$Shutdown_button.BackgroundImage = $Image_Shutdown
$Shutdown_button.Add_Click($Shutdown_button_Click)

$form_MainForm.Controls.Add($Shutdown_button)

提前感谢。

使用按钮上的属性
BackgroundImageLayout
。 就像这样:

$Shutdown_button.BackgroundImageLayout = "Center"

注意:将我的评论转换为答案,因为这是解决方案。

试试:$Shutdown\u button.BackgroundImageLayout=“Center”Super!!!它正在工作。多谢各位。祝你今天愉快。:)我补充了我的评论作为回答。请接受它作为一个答案,这样其他人就可以看到这个问题已经解决了。我接受了你的回答:)虽然没有“Powershell表单”。它被称为“Windows窗体”-通过寻找合适的术语,您将获得更好的搜索结果。(Powershell基于.NET,Windows窗体基于.NET,这就是为什么您可以在Powershell中使用该技术,但它不是特定于Powershell的。)