1

I have a PowerShell script with a borderless window and as more and more people use DPI scaling I tested my form accordingly.

Oddly it seems to scale (somewhat) well up to 150%, but with 175% the form itself (red) grows much more than the richtextbox (gray), as seen in the example below.

Any ideas on how to fix or prevent that?

[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$form = New-Object System.Windows.Forms.Form
$form.Size = "200,200"
$form.FormBorderStyle = "None"
$form.BackColor = "#C15959" 
$form.TopMost = $true
$form.StartPosition = "CenterScreen"

$form.AutoScalemode = "Dpi"
$form.AutoSize = $true
$form.AutoSizeMode = "GrowOnly"

$rtb = New-Object System.Windows.Forms.RichTextBox
$rtb.BorderStyle = "FixedSingle"
$rtb.BackColor = "#EDEDED"
$rtb.Anchor = "Top,Bottom,Right,Left"
$rtb.Size = "181,155"
$rtb.Location = "1,1"
$rtb.AutoSize = $true

$rtb.add_mouseclick({ $form.close()})
$form.Controls.Add($rtb)
$form.showdialog()

Form at 100% DPI scaling:

Form at 100% DPI scaling

Form at 175% DPI scaling:

enter image description here

Moss
  • 325
  • 2
  • 16
  • Seems to be a duplicate of [How to write WinForms code that auto-scales to system font and dpi settings?](http://stackoverflow.com/a/29766847/608772). – JPBlanc Mar 25 '16 at 05:22
  • Well if you think that it is a duplicate, you can surly point out what exactly in the linked thread would solve my problem. I don't see anything there that applies here. – Moss Mar 25 '16 at 11:09
  • As fas as I can read in your code, you do not apply all the rules in the answer I point. – JPBlanc Mar 25 '16 at 12:50
  • Look, you found a thread that has a similar topic. That is, if you ignore that fact that its mostly about Visual Studio and C#. And about proper font scaling. So far so good. It has some interesting information, but none of those help here. I tried it. And one thing it is clearly not: a duplicate – Moss Mar 25 '16 at 14:34
  • What about : "All ContainerControls must also be set with AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F)". Your form is a container. And PowerShell is only a way to call the same objects as C# – JPBlanc Mar 25 '16 at 16:23
  • It is weird that you keep insisting that the solution is in there, despite the fact that I told you that I tried the recommendations in the thread and you clearly did not test it yourself. So I'll end this conversation now. – Moss Mar 25 '16 at 17:00

1 Answers1

0

The solution is not to set size but clientsize for the form itself.

Moss
  • 325
  • 2
  • 16