如何使用Powershell表单正确执行此操作?

时间:2018-09-10 09:52:56

标签: winforms powershell

最近,我开始熟悉Powershell中的Windows窗体,我想创建一个带有图片的按钮。图片显示在按钮上,但采用马赛克样式。是否有解决方案可以将图片保持在按钮的中央?

Here is the picture about what I can see and what I want to see

这是我的代码:

$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)

谢谢。

1 个答案:

答案 0 :(得分:1)

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

$Shutdown_button.BackgroundImageLayout = "Center"

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