Skip to content

Fix ScrollableControl scrollbar synchronization after property-driven display position updates#14658

Open
abineshPalanisamy wants to merge 3 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_3614
Open

Fix ScrollableControl scrollbar synchronization after property-driven display position updates#14658
abineshPalanisamy wants to merge 3 commits into
dotnet:mainfrom
abineshPalanisamy:Fix_Issue_3614

Conversation

@abineshPalanisamy

@abineshPalanisamy abineshPalanisamy commented Jun 18, 2026

Copy link
Copy Markdown

Fixes #3614

Proposed changes

  • Update ScrollableControl.SetDisplayFromScrollProps(int x, int y) to explicitly call SyncScrollbars(true) after SetDisplayRectLocation(x, y). This ensures that the scrollbar state is synchronized after the display rectangle position changes through the property-driven scroll path.
  • Preserve the existing SetDisplayFromScrollProps flow while completing the missing scrollbar synchronization step required after the display position is updated.
  • Add unit test coverage in ScrollableControlTests for property-driven horizontal scroll position updates to verify that display position changes and scrollbar synchronization remain consistent. The WinForms test suite already contains ScrollableControlTests.cs, which is the appropriate location for this regression coverage.

Root cause

  • The issue occurs in the property-driven scroll path where ScrollProperties.Value updates the display position via SetDisplayFromScrollProps(...).
  • SetDisplayRectLocation(int x, int y) updates the display position but does not update the scrollbar state.
  • Since no synchronization step was performed afterward, the display rectangle and scrollbar state became inconsistent, causing stale UI during continuous scrolling.
  • Other WinForms paths already pair SetDisplayRectLocation(...) with SyncScrollbars(true), which was missing in this path.

Customer Impact

  • Fixes the stale UI/content issue that occurs when the horizontal scroll position is updated through the property-driven path during the continuous drag scenario described in the issue. After the fix, the visible panel content stays aligned with the final scrollbar position.
  • Prevents cases where the scrollbar position changes correctly but the displayed content does not update to reflect the new horizontal position until a later layout or synchronization step occurs.

Regression?

  • No

Risk

  • Low.
  • The change is scoped only to ScrollableControl.SetDisplayFromScrollProps(...), which is invoked through the property-driven scroll update path (ScrollProperties.UpdateDisplayPosition()).
  • Adds only the missing synchronization step (SyncScrollbars(true)) after SetDisplayRectLocation(...), aligning with existing ScrollableControl patterns used in other position update paths.
  • No layout changes; avoids broader side effects.

Screenshots

Before

Scrollable_Before_fix.mp4

After

Scrollable_After_fix.mp4

Test methodology

  • Reproduced the issue scenario described in the GitHub issue, where the horizontal scrollbar position changes through the drag/outside/re-enter interaction and the visible content becomes stale.
  • Verified that calling SyncScrollbars(true) after SetDisplayRectLocation(...) resolves the inconsistency between the display rectangle position and the scrollbar state in the property-driven path.
  • Added unit tests in ScrollableControlTests to validate that:
    • updating the display position through SetDisplayFromScrollProps(...) synchronizes the managed and native horizontal scrollbar positions, and
    • repeated property-driven horizontal position updates remain synchronized.
  • Verified that the fix addresses the missing synchronization step without changing the broader scrollbar recalculation behavior outside this path.

Accessibility testing

Test environment(s)

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

Added the fix for the Fix_Issue_3614
Added the unit test cases for Fix_Issue_3614

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.

Pull request overview

This PR fixes a scrollbar state desynchronization in ScrollableControl when the display position is updated via the ScrollProperties.Value (property-driven) path, addressing #3614.

Changes:

  • Synchronize scrollbars after SetDisplayRectLocation(x, y) in ScrollableControl.SetDisplayFromScrollProps(int x, int y) by calling SyncScrollbars(true).
  • Add regression tests to verify managed (HorizontalScroll.Value) and native (GetScrollInfo) horizontal scroll positions remain aligned after property-driven display position updates.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/System.Windows.Forms/System/Windows/Forms/Scrolling/ScrollableControl.cs Adds a missing SyncScrollbars(true) call to keep native and managed scrollbar state consistent after display rect updates from scroll properties.
src/test/unit/System.Windows.Forms/System/Windows/Forms/ScrollableControlTests.cs Adds tests validating horizontal display offset updates keep DisplayRectangle, managed scroll value, and native scrollbar position in sync.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/test/unit/System.Windows.Forms/System/Windows/Forms/ScrollableControlTests.cs Outdated
Addressed the review correction for Fix_Issue_3614
@abineshPalanisamy

Copy link
Copy Markdown
Author

@dotnet-policy-service agree company="Syncfusion, Inc."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DTS: USER32!SetScrollInfo is not called as expected when you drag the scrollbar over the window

2 participants