Fix icons of PropertyGrid control are not scaled well on 100% secondary monitor - #14828
Open
ricardobossan wants to merge 2 commits into
Open
Fix icons of PropertyGrid control are not scaled well on 100% secondary monitor#14828ricardobossan wants to merge 2 commits into
ricardobossan wants to merge 2 commits into
Conversation
…ry monitor Fixes dotnet#8268 ## Proposed changes `PropertyGrid`'s toolbar icons (sort-alphabetically / sort-by-category / property-pages buttons) didn't rescale correctly after a PerMonitorV2 DPI change. Root-caused to two independent, stacked defects in the toolbar rebuild path (`PropertyGrid.SetupToolbar`/`CreatePushButton`): - `SetupToolbar()` rebuilt the toolbar's `ImageList` at the new DPI but never updated `ToolStrip.ImageScalingSize` (what actually drives rendered icon size), and the `ImageList.ImageSize` assignment itself was gated on `ScaleHelper.IsScalingRequired`, which only reflects the _process's_ startup DPI rather than whether the app is PerMonitorV2-aware. Fixed by always setting `ImageScalingSize` right after the `ImageList` is rebuilt; before any button is created, since a `ToolStripItem`'s size is computed once and never revisited later; and switching to `ScaleHelper.IsScalingRequirementMet`. - `ToolStripItem`/`ToolStripButton` bake their default `Margin` and minimum button width from `ScaleHelper.InitialSystemDpi` (again the process's startup DPI) at construction time, so a button (re)created after a runtime DPI change still inherits sizing baked in for whatever DPI the process happened to start at. Fixed by having `CreatePushButton` explicitly re-apply `Margin` and `DeviceDpi` using the grid's current DPI; `DeviceDpi` routes through `ToolStripButton`'s own already-correct `DeviceDpi` setter override, which recomputes the minimum width but was never being invoked for ordinary toolbar buttons. Together these explain the issue's reported asymmetry: sizing baked in for a _higher_ DPI and later applied at a _lower_ one is very visibly wrong (oversized icons/buttons); the reverse just leaves a little extra room, so it's easy to miss. ## Customer Impact - Apps using `PerMonitorV2` render `PropertyGrid` toolbar icons at the wrong size after the app moves between monitors with different DPI, until the process restarts. Visual/readability issue only; the grid remains fully usable. ## Regression? - Yes, relative to .NET Framework; not a regression within .NET Core/5+ (reproduces on .NET 6/7/8 alike per the issue). ## Risk - All changes are scoped to `PropertyGrid`'s own toolbar-button construction/rebuild path; none affect `SystemAware`/`DpiUnaware` apps or any other control. The `DeviceDpi`/`IsScalingRequirementMet` changes invoke existing, already-correct framework code paths rather than introducing new logic. <!-- end TELL-MODE-->> ### Before ### After ## Test environment(s) <!-- Remove any that don't apply-->> 11.0.100-preview.5.26302.115
Member
|
LGTM! Could you please check the following:
|
LeafShi1
reviewed
Jul 31, 2026
LeafShi1
reviewed
Jul 31, 2026
Member
Author
@SimonZhao888 Thanks for checking, both confirmed now with the actual repro app across real monitors at different scales:
Both should be good to go. |
SimonZhao888
approved these changes
Aug 4, 2026
LeafShi1
approved these changes
Aug 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #8268
Proposed changes
PropertyGrid's toolbar icons (sort-alphabetically / sort-by-category / property-pages buttons) didn't rescale correctly after a PerMonitorV2 DPI change. Root-caused to two independent, stacked defects in the toolbar rebuild path (PropertyGrid.SetupToolbar/CreatePushButton):SetupToolbar()rebuilt the toolbar'sImageListat the new DPI but never updatedToolStrip.ImageScalingSize(what actually drives rendered icon size), and theImageList.ImageSizeassignment itself was gated onScaleHelper.IsScalingRequired, which only reflects the process's startup DPI rather than whether the app is PerMonitorV2-aware. Fixed by always settingImageScalingSizeright after theImageListis rebuilt; before any button is created, since aToolStripItem's size is computed once and never revisited later; and switching toScaleHelper.IsScalingRequirementMet.ToolStripItem/ToolStripButtonbake their defaultMarginand minimum button width fromScaleHelper.InitialSystemDpi(again the process's startup DPI) at construction time, so a button (re)created after a runtime DPI change still inherits sizing baked in for whatever DPI the process happened to start at. Fixed by havingCreatePushButtonexplicitly re-applyMarginandDeviceDpiusing the grid's current DPI;DeviceDpiroutes throughToolStripButton's own already-correctDeviceDpisetter override, which recomputes the minimum width but was never being invoked for ordinary toolbar buttons.Together these explain the issue's reported asymmetry: sizing baked in for a higher DPI and later applied at a lower one is very visibly wrong (oversized icons/buttons); the reverse just leaves a little extra room, so it's easy to miss.
Customer Impact
PerMonitorV2renderPropertyGridtoolbar icons at the wrong size after the app moves between monitors with different DPI, until the process restarts. Visual/readability issue only; the grid remains fully usable.Regression?
Risk
PropertyGrid's own toolbar-button construction/rebuild path; none affectSystemAware/DpiUnawareapps or any other control. TheDeviceDpi/IsScalingRequirementMetchanges invoke existing, already-correct framework code paths rather than introducing new logic.Before
After
Test environment
11.0.100-preview.5.26302.115
Microsoft Reviewers: Open in CodeFlow