Skip to content

Fix Disabled RichTextBox renders BackColor in padding area but not in client area under NET11 VisualStylesMode - #15164

Open
Sathish-087 wants to merge 7 commits into
dotnet:mainfrom
Sathish-087:Fix_Issue_15053
Open

Sathish-087 wants to merge 7 commits into
dotnet:mainfrom
Sathish-087:Fix_Issue_15053

Conversation

@Sathish-087

@Sathish-087 Sathish-087 commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15053

Proposed changes

  • Unified disabled RichTextBox background color selection for Net11 visual styles so that the native RichEdit client area and WinForms-managed padding area use the same effective background color.
  • Updated TextBoxBase Net11 non-client painting to use a shared effective background color decision for enabled and disabled states.
  • Added repaint/invalidation handling for enabled state transitions and synchronized RichEdit background updates through EM_SETBKGNDCOLOR.

Customer Impact

  • Disabled RichTextBox controls no longer display mismatched background colors between the client area and padding area when using VisualStylesMode.Net11.
  • RichTextBox controls with custom BackColor settings now maintain a visually consistent surface across enabled/disabled state changes.

Regression?

  • No

Risk

  • Low. The change is limited to Net11 RichTextBox/TextBoxBase rendering behavior and background-color synchronization paths.
  • Existing control functionality, editing behavior, and non-Net11 rendering paths remain unchanged.
  • Added regression tests covering disabled rendering, background-color updates, and enabled-state transitions.

Screenshots

Before

image

After

image

Test methodology

  • Verified disabled RichTextBox rendering behavior with VisualStylesMode.Net11 and explicit BackColor values.
  • Verified disabled RichTextBox behavior without an explicit BackColor.
  • Verified BackColor changes correctly update the native RichEdit background path.
  • Verified enabled-to-disabled transitions repaint the control and invalidate the Net11 non-client area.
  • Executed existing WinForms unit test suite covering RichTextBox and TextBoxBase behavior.
  • Performed manual validation using the issue reproduction scenario with padding and Net11 visual styles.

Accessibility testing

Test environment(s)

  • .NET 11 Preview
  • Windows 11
  • x64
  • 100% UI scaling
  • VisualStylesMode.Net11 enabled
Microsoft Reviewers: Open in CodeFlow

@codecov

codecov Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.84861%. Comparing base (799c47a) to head (94213cb).
⚠️ Report is 18 commits behind head on main.

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15164   +/-   ##
=============================================
  Coverage   37.84861%   37.84861%           
=============================================
  Files            246         246           
  Lines           9789        9789           
  Branches        1031        1031           
=============================================
  Hits            3705        3705           
  Misses          5920        5920           
  Partials         164         164           
Flag Coverage Δ
Debug 37.84861% <ø> (ø)
production 40.04608% <ø> (ø)
test 20.64923% <ø> (ø)
unit 40.04608% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

One or more issues must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 1 Low severity

Open (1)
What changed in this PR

Fixes disabled RichTextBox background inconsistencies under .NET 11 visual styles.

Changes:

  • Unifies disabled background-color selection.
  • Invalidates modern non-client rendering on enabled-state changes.
  • Adds RichTextBox and TextBoxBase regression tests.
File Description
src/​test/​unit/​System.Windows.Forms/​TextBoxBaseTests.cs Updated as part of this pull request.
src/​test/​unit/​System.Windows.Forms/​System/​Windows/​Forms/​RichTextBoxTests.cs Updated as part of this pull request.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Controls/​TextBox/​TextBoxBase.cs Updated as part of this pull request.
src/​System.Windows.Forms/​System/​Windows/​Forms/​Controls/​RichTextBox/​RichTextBox.cs Updated as part of this pull request.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1243 to +1247
control.ResetTrackedMessages();
control.Invalidate();
control.Update();

Assert.True(control.PaintMessageReceived);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the regression test to render the control and compare the disabled RichTextBox client and padding background colors directly. I also added a sentinel color check to ensure both regions were rendered, preventing false-positive results.

@LeafShi1
LeafShi1 requested a review from SimonZhao888 October 15, 2026 02:22

@SimonZhao888 SimonZhao888 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the disabled effective background is now synchronized into the native RichEdit through EM_SETBKGNDCOLOR, could we also verify the round-trip Enabled -> Disabled -> Enabled behavior for both the default and an explicitly assigned BackColor?

In particular, I want to make sure the native client area restores the correct enabled background rather than retaining the disabled color. It may also be worth covering a BackColor change while the control is disabled.

@Sathish-087

Copy link
Copy Markdown
Contributor Author

Since the disabled effective background is now synchronized into the native RichEdit through EM_SETBKGNDCOLOR, could we also verify the round-trip Enabled -> Disabled -> Enabled behavior for both the default and an explicitly assigned BackColor?

In particular, I want to make sure the native client area restores the correct enabled background rather than retaining the disabled color. It may also be worth covering a BackColor change while the control is disabled.

Updated the regression test to render the control and compare the disabled RichTextBox client and padding background colors directly. I also added a sentinel color check to ensure both regions were rendered, preventing false-positive results.

@SimonZhao888 SimonZhao888 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@SimonZhao888 SimonZhao888 added the waiting-review This item is waiting on review by one or more members of team label Oct 20, 2026
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.

Disabled RichTextBox renders BackColor in padding area but not in client area under NET11 VisualStylesMode

3 participants