Skip to content

Commit 5a9fb88

Browse files
authored
Scale the Anchor editor according to DPI (#13853)
<!-- Please read CONTRIBUTING.md before submitting a pull request --> Related #13830 ## Proposed changes - Update the `InitializeComponent` method to draw the Anchor Editor using the scaled size instead of hard-coding it. <!-- We are in TELL-MODE the following section must be completed --> ## Customer Impact - On High DPI environment, Anchor editor in propertyGrid can be scaled well ## Regression? - No ## Risk - Minimal <!-- end TELL-MODE --> ## Screenshots <!-- Remove this section if PR does not change UI --> ### Before In 300% DPI: <img width="1783" height="750" alt="image" src="https://github.com/user-attachments/assets/e7373f7c-db87-4b56-a370-b98e14da03aa" /> ### After In 300% DPI: <img width="1281" height="846" alt="image" src="https://github.com/user-attachments/assets/c5c7560a-fcf1-42ba-97a9-32ed69e01470" /> ## Test methodology <!-- How did you ensure quality? --> - Manually ## Test environment(s) <!-- Remove any that don't apply --> - .net 10.0.0-rc.1.25454.102 <!-- Mention language, UI scaling, or anything else that might be relevant --> ###### Microsoft Reviewers: [Open in CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/dotnet/winforms/pull/13853)
2 parents 54eae4a + 8b7f313 commit 5a9fb88

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

src/System.Windows.Forms.Design/src/System/Windows/Forms/Design/AnchorEditor.AnchorUI.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,44 +69,51 @@ public virtual AnchorStyles GetSelectedAnchor()
6969

7070
internal virtual void InitializeComponent()
7171
{
72-
int XBORDER = SystemInformation.Border3DSize.Width;
73-
int YBORDER = SystemInformation.Border3DSize.Height;
72+
int XBORDER = ScaleHelper.ScaleToInitialSystemDpi(SystemInformation.Border3DSize.Width);
73+
int YBORDER = ScaleHelper.ScaleToInitialSystemDpi(SystemInformation.Border3DSize.Height);
7474
SuspendLayout();
75-
SetBounds(0, 0, 90, 90);
75+
76+
var pixel_10 = ScaleHelper.ScaleToInitialSystemDpi(10);
77+
var pixel_30 = ScaleHelper.ScaleToInitialSystemDpi(30);
78+
var pixel_40 = ScaleHelper.ScaleToInitialSystemDpi(40);
79+
var pixel_60 = ScaleHelper.ScaleToInitialSystemDpi(60);
80+
var pixel_90 = ScaleHelper.ScaleToInitialSystemDpi(90);
81+
82+
SetBounds(0, 0, pixel_90, pixel_90);
7683

7784
AccessibleName = SR.AnchorEditorAccName;
7885

7986
_container.Location = new Point(0, 0);
80-
_container.Size = new Size(90, 90);
87+
_container.Size = new Size(pixel_90, pixel_90);
8188
_container.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
8289

83-
_control.Location = new Point(30, 30);
84-
_control.Size = new Size(30, 30);
90+
_control.Location = new Point(pixel_30, pixel_30);
91+
_control.Size = new Size(pixel_30, pixel_30);
8592
_control.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right;
8693

87-
_right.Location = new Point(60, 40);
88-
_right.Size = new Size(30 - XBORDER, 10);
94+
_right.Location = new Point(pixel_60, pixel_40);
95+
_right.Size = new Size(pixel_30 - XBORDER, pixel_10);
8996
_right.TabIndex = 2;
9097
_right.TabStop = true;
9198
_right.Anchor = AnchorStyles.Right;
9299
_right.AccessibleName = SR.AnchorEditorRightAccName;
93100

94-
_left.Location = new Point(XBORDER, 40);
95-
_left.Size = new Size(30 - XBORDER, 10);
101+
_left.Location = new Point(XBORDER, pixel_40);
102+
_left.Size = new Size(pixel_30 - XBORDER, pixel_10);
96103
_left.TabIndex = 0;
97104
_left.TabStop = true;
98105
_left.Anchor = AnchorStyles.Left;
99106
_left.AccessibleName = SR.AnchorEditorLeftAccName;
100107

101-
_top.Location = new Point(40, YBORDER);
102-
_top.Size = new Size(10, 30 - YBORDER);
108+
_top.Location = new Point(pixel_40, YBORDER);
109+
_top.Size = new Size(pixel_10, pixel_30 - YBORDER);
103110
_top.TabIndex = 1;
104111
_top.TabStop = true;
105112
_top.Anchor = AnchorStyles.Top;
106113
_top.AccessibleName = SR.AnchorEditorTopAccName;
107114

108-
_bottom.Location = new Point(40, 60);
109-
_bottom.Size = new Size(10, 30 - YBORDER);
115+
_bottom.Location = new Point(pixel_40, pixel_60);
116+
_bottom.Size = new Size(pixel_10, pixel_30 - YBORDER);
110117
_bottom.TabIndex = 3;
111118
_bottom.TabStop = true;
112119
_bottom.Anchor = AnchorStyles.Bottom;

0 commit comments

Comments
 (0)