Reputation: 49
Recently, I have started getting acquainted with the windows forms in Powershell and I would like to create a button with a picture on it. The picture appears on a button but in mosaic styles. Is there a solution to keep the picture on the center of the button?
Here is the picture about what I can see and what I want to see
Here is my code:
$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)
Thank you in advance.
Upvotes: 0
Views: 532
Reputation: 2434
Use the property BackgroundImageLayout
from the button.
Like that:
$Shutdown_button.BackgroundImageLayout = "Center"
Note: Converted my comment to an answer beacuse it was the solution.
Upvotes: 2