-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix icons of PropertyGrid control are not scaled well on 100% secondary monitor #14828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1753,12 +1753,19 @@ private PropertyGridToolStripButton CreatePushButton( | |
| EventHandler eventHandler, | ||
| bool useRadioButtonRole = false) | ||
| { | ||
| // ToolStripItem/ToolStripButton bake Margin and the minimum button width from | ||
| // ScaleHelper.InitialSystemDpi (the process's startup DPI) at construction time. Re-apply both | ||
| // explicitly so a button (re)created after a runtime DPI change reflects the grid's actual current | ||
| // DPI; DeviceDpi routes through ToolStripButton's own existing, correct DeviceDpi setter override. | ||
| // See https://github.com/dotnet/winforms/issues/8268. | ||
| PropertyGridToolStripButton button = new(this, useRadioButtonRole) | ||
| { | ||
| Text = toolTipText, | ||
| AutoToolTip = true, | ||
| DisplayStyle = ToolStripItemDisplayStyle.Image, | ||
| ImageIndex = imageIndex | ||
| ImageIndex = imageIndex, | ||
| Margin = ScaleHelper.ScaleToDpi(new Padding(0, 1, 0, 2), DeviceDpi), | ||
| DeviceDpi = DeviceDpi | ||
| }; | ||
|
|
||
| button.Click += eventHandler; | ||
|
|
@@ -2106,7 +2113,7 @@ private void EnsureLargeButtons() | |
| ImageSize = s_largeButtonSize | ||
| }; | ||
|
|
||
| if (ScaleHelper.IsScalingRequired) | ||
| if (ScaleHelper.IsScalingRequirementMet) | ||
| { | ||
| AddLargeImage(_alphaBitmap); | ||
| AddLargeImage(_categoryBitmap); | ||
|
|
@@ -2140,7 +2147,7 @@ private void EnsureLargeButtons() | |
| } | ||
| } | ||
|
|
||
| // This method should be called only inside a if (DpiHelper.IsScalingRequired) clause. | ||
| // This method should be called only inside a if (ScaleHelper.IsScalingRequirementMet) clause. | ||
| private void AddLargeImage(Bitmap? originalBitmap) | ||
| { | ||
| if (originalBitmap is null) | ||
|
|
@@ -3874,12 +3881,19 @@ private void SetupToolbar(bool fullRebuild) | |
| { | ||
| _normalButtonImages?.Dispose(); | ||
| _normalButtonImages = new ImageList(); | ||
| if (ScaleHelper.IsScalingRequired) | ||
| if (ScaleHelper.IsScalingRequirementMet) | ||
| { | ||
| _normalButtonImages.ImageSize = s_normalButtonSize; | ||
| } | ||
| } | ||
|
|
||
| // A ToolStripItem's size is computed once, at creation, and never revisited on its own; set | ||
| // ImageScalingSize (drives ToolStripItem.PreferredImageSize) before CreatePushButton runs below. | ||
| if (!LargeButtons) | ||
| { | ||
| _toolStrip.ImageScalingSize = _normalButtonImages.ImageSize; | ||
| } | ||
|
|
||
| // Setup our event handlers. | ||
| EventHandler tabButtonHandler = OnViewTabButtonClick; | ||
| EventHandler sortButtonHandler = OnViewSortButtonClick; | ||
|
|
@@ -4013,6 +4027,9 @@ private void SetupToolbar(bool fullRebuild) | |
|
|
||
| _toolStrip.ImageList = LargeButtons ? _largeButtonImages : _normalButtonImages; | ||
|
|
||
| // Covers LargeButtons only (_largeButtonImages isn't ready earlier); a no-op otherwise. | ||
| _toolStrip.ImageScalingSize = LargeButtons ? _largeButtonImages!.ImageSize : _normalButtonImages!.ImageSize; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion (readability + DRY): since _toolStrip.ImageScalingSize = _toolStrip.ImageList!.ImageSize;This is runtime-equivalent to the current line, but keeps |
||
|
|
||
| using (SuspendLayoutScope scope = new(_toolStrip)) | ||
| { | ||
| _toolStrip.Items.Clear(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This early
ImageScalingSizeassignment looks redundant — the later unconditional set (_toolStrip.ImageScalingSize = LargeButtons ? ... : _normalButtonImages!.ImageSize;) already runs before the newly created buttons are added to the ToolStrip and laid out, and for the!LargeButtonscase both assign the identical value (_normalButtonImages.ImageSize).The stated rationale ("set before
CreatePushButtonruns, since aToolStripItem's size is computed once at creation") doesn't seem to hold here:PropertyGridToolStripButtondoesn't set the ToolStrip as itsOwnerat construction (it only stores the grid in_owningPropertyGrid), so duringCreatePushButtonthe button'sOwnerisnull. SinceToolStripItem.PreferredImageSizereadsOwner.ImageScalingSizedynamically and returnsSize.EmptywhenOwner is null, the effective size is bound at layout time — which happens after_toolStrip.Items.Add(...), i.e. after the later assignment has already set the correct value.Could you double-check whether dropping this
if (!LargeButtons)block (keeping only the later assignment) still fixes the issue with a "start 100% → move to 225%" repro? If so, this block and its comment can likely be removed. If there is a layout-cache subtlety that makes it necessary, it'd be great to capture that in the comment instead.