I'm new to PowerShell and now I got to forms.
And I have a problem that I cannot solve in any way.
I made a form with buttons, textboxes and labels. I have set a fixed size for each item.
Form opens normally on most PCs
But on some, it opens like this:
And I don't understand how to fix it at all. I spent a whole day on this. I have already used
$objForm.AutoScaleMode = 'dpi'
$objForm.AutoScaleDimensions = '6, 13'
But that doesn't help.
Please, tell me how to make the form look normal for everyone.
Thanks!
UPD: I made sure that this effect is achieved by changing the scale to 125% But I never found a solution.
P.S. Sorry for bad English :-)
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Computer Connect"
$objForm.Size = New-Object System.Drawing.Size(280,350)
$objForm.StartPosition = "CenterScreen"
$objForm.BackColor = "Lightblue"
$objForm.KeyPreview = $True
$objForm.Topmost = $True
$objForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
$objForm.Add_Shown({$objForm.Activate()})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Down")
{
$objListbox.SelectedIndex = $objListbox.SelectedIndex + 1
}
})
$objForm.Add_KeyDown({if ($_.KeyCode -eq "Up")
{
$objListbox.SelectedIndex = $objListbox.SelectedIndex - 1
}})
#BUTTON DW ADM
$HistoryRange = New-Object System.Windows.Forms.Listbox
$RCButton = New-Object System.Windows.Forms.Button
$RCButton.Location = New-Object System.Drawing.Size(10,160)
$RCButton.Size = New-Object System.Drawing.Size(75,23)
$RCButton.Text = "DW ADM"
$objForm.Controls.Add($RCButton)
#BUTTON DameWare
$DWButton = New-Object System.Windows.Forms.Button
$DWButton.Location = New-Object System.Drawing.Size(100,160)
$DWButton.Size = New-Object System.Drawing.Size(75,23)
$DWButton.Text = "DameWare"
$objForm.Controls.Add($DWButton)
##-------VDI BUTTON-
$VDIButton = New-Object System.Windows.Forms.Button
$VDIButton.Location = New-Object System.Drawing.Size(190,240)
$VDIButton.Size = New-Object System.Drawing.Size(75,23)
$VDIButton.Text = "VDI"
$objForm.Controls.Add($VDIButton)
#-----------------------------------------------------------------------
$VDIInput = New-Object System.Windows.Forms.TextBox
$VDIInput.Location = New-Object System.Drawing.Size(10,295)
$VDIInput.Size = New-Object System.Drawing.Size(255)
$objForm.Controls.Add($VDIInput)
#-----------------------------------------------------------------------
#BUTTON LOCK.RU
$InfoButton = New-Object System.Windows.Forms.Button
$InfoButton.Location = New-Object System.Drawing.Size(190,160)
$InfoButton.Size = New-Object System.Drawing.Size(75,23)
$InfoButton.Text = "lock.ru"
$objForm.Controls.Add($InfoButton)
##-------HELP BUTTON-
$HELPButton = New-Object System.Windows.Forms.Button
$HELPButton.Location = New-Object System.Drawing.Size(115, 190)
$HELPButton.Size = New-Object System.Drawing.Size(75, 23)
$HELPButton.Text = "HELP"
$objForm.Controls.Add($HELPButton)
#LOGGED ON
$Info = New-Object System.Windows.Forms.Button
$Info.Location = New-Object System.Drawing.Size(190,215)
$Info.Size = New-Object System.Drawing.Size(75,23)
$Info.Text = "Logged On machines"
$objForm.Controls.Add($Info)
#PING LABEL
$IPlabel1 = New-Object System.Windows.Forms.Label
$IPlabel1.Location = New-Object System.Drawing.Size(100,193)
$IPlabel1.Size = New-Object System.Drawing.Size(80,15)
$IPlabel1.Text = ""
$objForm.Controls.Add($IPlabel1)
$IPLabel = New-Object System.Windows.Forms.Label
$IPLabel.Location = New-Object System.Drawing.Size(10,193)
$IPLabel.Size = New-Object System.Drawing.Size(80,15)
$IPLabel.Text = "IP-адрес:"
$objForm.Controls.Add($IPLabel)
$MACLabel = New-Object System.Windows.Forms.Label
$MACLabel.Location = New-Object System.Drawing.Size(10,215)
$MACLabel.Size = New-Object System.Drawing.Size(80,15)
$MACLabel.Text = "MAC-адрес:"
$objForm.Controls.Add($MACLabel)
$MACaddress = New-Object System.Windows.Forms.label
$MACaddress.Location = New-Object System.Drawing.Size(100,215)
$MACaddress.Size = New-Object System.Drawing.Size(80,15)
$objForm.Controls.Add($MACaddress)
$pingLabel = New-Object System.Windows.Forms.Label
$PingLabel.Location = New-Object System.Drawing.Size(10,233)
$PingLabel.Size = New-Object System.Drawing.Size(170,60)
$PingLabel.Text = "Ping"
$PingLabel.AutoSize = $True
$objForm.Controls.Add($PingLabel)
#Button to UNLOCK
$UnlockButton = New-Object System.Windows.Forms.Button
$UnlockButton.Location = New-Object System.Drawing.Size(190,190)
$UnlockButton.Size = New-Object System.Drawing.Size(75,23)
$UnlockButton.Text = "UNLOCK"
$objForm.Controls.Add($UnlockButton)
#LABEL ПОИСК
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,18)
$objLabel.Size = New-Object System.Drawing.Size(40,20)
$objLabel.Text = "Поиск:"
$objForm.Controls.Add($objLabel)
#BUTTON Clear
$ClearButton = New-Object System.Windows.Forms.Button
$ClearButton.Location = New-Object System.Drawing.Size(172,12)
$ClearButton.Size = New-Object System.Drawing.Size(40,23)
$ClearButton.Text = "Clear"
$objForm.Controls.Add($ClearButton)
#BUTTON HISTORY
$HistoryButton = New-Object System.Windows.Forms.Button
$HistoryButton.Location = New-Object System.Drawing.Size(214,12)
$HistoryButton.Size = New-Object System.Drawing.Size(50,23)
$HistoryButton.Text = "History"
$objForm.Controls.Add($HistoryButton)
#TEXT BOX
$objInput = New-Object System.Windows.Forms.TextBox
$objInput.Location = New-Object System.Drawing.Size(50,15)
$objInput.Size = New-Object System.Drawing.Size(115)
$objForm.Controls.Add($objInput)
#LIST-BOX
$objListbox = New-Object System.Windows.Forms.Listbox
$objListbox.Location = New-Object System.Drawing.Size(10,43)
$objListbox.Size = New-Object System.Drawing.Size(253,20)
$objListbox.Height = 120
$objForm.Controls.Add($objListbox)
[void] $objForm.ShowDialog()