高 DPI powershell 形式

High DPI powershell form

我创建了一个表格来提供有关您所用计算机的信息,当我们将其部署到 Surface pro 4 时,我们没有考虑 DPI,它在测试中爆炸并且在表格中不可读。见下文。

错误的形式:

它应该是这样的:

我已经尝试了所有的 AutoSizeMode 并将其放入组和表中,但似乎没有任何效果。我把它放在 Whosebug 上,看看是否有人有好的解决方案。这是我的基础表格:

#Background Image
$Image = [system.drawing.image]::FromFile("Desktop.jpg")

$Form.BackgroundImage = $Image

$Form.BackgroundImageLayout = "Stretch"


#button
$Button = New-Object System.Windows.Forms.Button 
$Button.TabIndex = 0 
$Button.Name = "Button" 
$System_Drawing_Size = New-Object System.Drawing.Size 
$System_Drawing_Size.Width = 160
$System_Drawing_Size.Height = 30 
$Button.Size = $System_Drawing_Size 
$Button.UseVisualStyleBackColor = $True

$Button.Text = "Button"
$System_Drawing_Point = New-Object System.Drawing.Point 
$System_Drawing_Point.X = 13
$System_Drawing_Point.Y = 230
$Button.Location = $System_Drawing_Point 
$Button.DataBindings.DefaultDataSourceUpdateMode = 0 
$Button.add_Click({Function1})


$Font = New-Object System.Drawing.Font("Calibri",11.5 [System.Drawing.FontStyle]::Regular)
$Form.Font = $Font


#Lables for the computer information and displays them
$Label = New-Object System.Windows.Forms.Label
$Label.Text = "`n Phone: $CallServiceDesk `n E-Mail: `n IP Address: $IPAddress `n Computer Name: $env:computername `n Username: $env:username `n     Domain: $env:userdomain `n HomeServer: $env:HOMESERVER `n AssetTag: $env:TIA `n Service Tag: $env:servicetagsn `n McAfee Proxy: $Proxy"
$Label.BackColor = "Transparent"
$Label.AutoSize = $True

$Form.Controls.Add($Email_Label)
$Form.Controls.Add($Call_Label)
$Form.Controls.Add($Label)
$Form.Controls.Add($Button)
$Form.Controls.Add($Learn_Label)


$Form.ShowDialog() 

if ($Form -eq "Cancel"){exit}

我通过在我的字体变量中添加 [System.Drawing.GraphicsUnit]::Pixel 来解决这个问题

$Font = New-Object System.Drawing.Font("Segoe UI",13,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Pixel)
$Form.Font = $Font