Skip to content

Fix ItemHeight of ListBox is not scaled on high DPI in OwnerDrawFixed mode#14740

Open
ricardobossan wants to merge 2 commits into
dotnet:mainfrom
ricardobossan:Issue_6382_ItemHeight_of_ListBox_is_not
Open

Fix ItemHeight of ListBox is not scaled on high DPI in OwnerDrawFixed mode#14740
ricardobossan wants to merge 2 commits into
dotnet:mainfrom
ricardobossan:Issue_6382_ItemHeight_of_ListBox_is_not

Conversation

@ricardobossan

@ricardobossan ricardobossan commented Jul 15, 2026

Copy link
Copy Markdown
Member

Fixes #6382

Proposed changes

An OwnerDrawFixed ListBox keeps its fixed ItemHeight (the reporter's sample sets 25) when the
control is autoscaled. At higher DPI the font grows but the rows stay their design-time height, so the
items look cramped. .NET Framework scaled the item height; .NET (Core) doesn't.

  • Scale the OwnerDrawFixed item height by factor.Height in ListBox.ScaleControl; the same
    scaling pass that already scales padding and margin. The result is clamped to [1, 255], and a
    height-axis guard keeps a partial pass from applying the factor twice.
  • ScaleControl is the entry point that both AutoScaleMode.Font/Dpi and PerMonitorV2 route
    through, so no per-DPI-message hook is needed.

Customer Impact

  • Owner-draw fixed ListBox items are the correct height at higher DPI instead of the design-time
    height. Long-standing customer report; does not occur on .NET Framework.

Regression?

  • Versus .NET Framework: yes (Framework scaled it, Core didn't). Not a recent .NET regression.

Risk

  • Low. Runs only for OwnerDrawFixed during a real scaling pass, reuses the ItemHeight setter, and
    clamps so it can't throw. Normal/OwnerDrawVariable unaffected.

Screenshots

Sample is HighDpiMode.SystemAware (reads DPI at startup): change the scale, then relaunch to

Before

before-150

150%: rows stay at ItemHeight = 25 while the font scales up (cramped).

After

after-150

150%: item height scales (25 > ~38), keeping the 100% proportions.

Test methodology

  • Unit tests

Accessibility testing

  • No accessibility surface change; item height only affects layout.

Test environment(s)

  • 11.0.100-preview.5.26302.115
Microsoft Reviewers: Open in CodeFlow

An `OwnerDrawFixed` `ListBox` keeps its fixed `ItemHeight` (the reporter's sample sets `25`) when the
control is autoscaled. At higher DPI the font grows but the rows stay their design-time height, so the
items look cramped. .NET Framework scaled the item height; .NET (Core) doesn't.

- Scale the `OwnerDrawFixed` item height by `factor.Height` in `ListBox.ScaleControl`; the same
  scaling pass that already scales padding and margin. The result is clamped to `[1, 255]`, and a
  height-axis guard keeps a partial pass from applying the factor twice.
- `ScaleControl` is the entry point that both `AutoScaleMode.Font`/`Dpi` and PerMonitorV2 route
  through, so no per-DPI-message hook is needed.

- Owner-draw fixed `ListBox` items are the correct height at higher DPI instead of the design-time
  height. Long-standing customer report; does not occur on .NET Framework.

- Versus .NET Framework: yes (Framework scaled it, Core didn't). Not a recent .NET regression.

- Low. Runs only for `OwnerDrawFixed` during a real scaling pass, reuses the `ItemHeight` setter, and
  clamps so it can't throw. `Normal`/`OwnerDrawVariable` unaffected.

Sample is `HighDpiMode.SystemAware` (reads DPI at startup): change the scale, then **relaunch** to

150%: rows stay at `ItemHeight = 25` while the font scales up (cramped).

150%: item height scales (25 > ~38), keeping the 100% proportions.

- Unit tests

- No accessibility surface change; item height only affects layout.

- Windows 11, .NET (main).
@ricardobossan ricardobossan self-assigned this Jul 15, 2026
@ricardobossan ricardobossan added the waiting-review This item is waiting on review by one or more members of team label Jul 15, 2026
@ricardobossan
ricardobossan requested a review from a team as a code owner July 15, 2026 00:32
@ricardobossan ricardobossan changed the title ItemHeight of ListBox is not scaled on high DPI in OwnerDrawFixed mode Fix ItemHeight of ListBox is not scaled on high DPI in OwnerDrawFixed mode Jul 15, 2026
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/ListBoxes/ListBox.cs Outdated
Math.Round uses banker's rounding by default, so .5 midpoints could round down (15 * 1.5 -> 22) and re-introduce the cramped rows this fixes.

Add tests covering the midpoints (25 -> 38, 15 -> 23) and the height-axis guard that keeps a Height-excluded scaling pass from applying the factor twice.
@ricardobossan
ricardobossan requested a review from LeafShi1 July 16, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-review This item is waiting on review by one or more members of team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ItemHeight of ListBox is not scaled on high DPI in OwnerDrawFixed mode

2 participants