I have a PowerShell GUI application in which i have to make changes but it is not showing properly. I have checked with different versions of PowerShell as well. Below are my results and its code.
Code:
Function welcomeScreen{
#Reading in .Net classes needed for forms.
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
#Create the windows
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Tool Wrapper " + $script:version + " Lab"
$objForm.Size = New-Object System.Drawing.Size(450,250)
$objForm.TopMost = $True
$objForm.StartPosition = "CenterScreen"
$objForm.FormBorderStyle = 'Fixed3D'
$objForm.MaximizeBox = $true
#$objForm.Opacity = 0.9
$Font = New-Object System.Drawing.Font("Segoe UI", 11,[System.Drawing.FontStyle]::Regular)
$objForm.Font = $Font
#Set keybinds for Enter and Esc keys
$objForm.KeyPreview = $True
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
{$x=$objTextBox.Text;$objForm.Close()}})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close()}})
#Welcome message
$objWelcome = New-Object System.Windows.Forms.label
$objWelcome.Location = New-Object System.Drawing.Size(30,20)
$objWelcome.Size = New-Object System.Drawing.Size(430,20)
$objWelcome.Text = "Welcome to the Migration Tool"
$objForm.Controls.Add($objWelcome)
#Display started button
$objStartButton = New-Object System.Windows.Forms.button
$objStartButton.Location = New-Object System.Drawing.Size(50,60)
$objStartButton.Size = New-Object System.Drawing.Size(200,30)
$objStartButton.Text = "Start Migration Process"
$objStartButton.Add_Click({
#find out who the current user is
Logger("User clicked to start migration process.");
Logger("Current user is: " + $script:currentUser)
$script:progressIndicator = 1;
$objForm.Close();
})
$objForm.Controls.Add($objStartButton)
#Create "Cancel" button
$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(270,60)
$CancelButton.Size = New-Object System.Drawing.Size(75,30)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({
$objForm.Close();
$script:progressIndicator = 0
})
$objForm.Controls.Add($CancelButton)
#Create fun message
$objFun = New-Object System.Windows.Forms.Label
$objFun.Location = New-Object System.Drawing.Size(50, 140)
$objFun.Size = New-Object System.Drawing.Size(400,60)
$objFun.Text = "Brought to you by the Infrastructure Services Team "
$MessageFont = New-Object System.Drawing.Font("Segoe UI", 11, [System.Drawing.FontStyle]::Italic)
$objFun.Font = $MessageFont
$objForm.Controls.Add($objFun)
$objForm.Topmost = $True
[void] $objForm.ShowDialog()
}
Results are below on different versions of PowerShell as well on different display size
In 5.1.22621.3880 PowerShell version for Large and small screen
In 5.1.22621.3672 PowerShell version for Large screen
In 5.1.22621.3672 PowerShell version for small screen
As I’m new to this any help will be thankful. Just wanted to show properly in both screens.
1