Skip to content

Fix issue 14693: TrackBar UI control doesn't reflect properties#14697

Open
SimonZhao888 wants to merge 10 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14693
Open

Fix issue 14693: TrackBar UI control doesn't reflect properties#14697
SimonZhao888 wants to merge 10 commits into
dotnet:mainfrom
SimonZhao888:Fix_Issue_14693

Conversation

@SimonZhao888

@SimonZhao888 SimonZhao888 commented Jul 2, 2026

Copy link
Copy Markdown
Member

Fixes #14693

Root Cause

This regression came from the manual tick-rendering path introduced in #8060.
When TrackBar falls back to DrawTicksManually(), the tick math had two issues:

  • The interior tick loop in DrawTicksManually() had an off-by-one boundary (<), so the last valid interior tick could be skipped.
  • Tick rendering was not refreshed on size changes when using manual ticks, so the UI could become stale after resize/property updates.

Proposed changes

  • Fixed the manual tick loop boundary in DrawTicksManually() from < to <= so the final valid interior tick is included.
  • Added TrackBar.OnSizeChanged(EventArgs) override to refresh ticks on resize。
    • Recreate the handle when auto/manual tick mode decision changes.
    • Otherwise redraw manual ticks and invalidate.
  • Added public API baseline entry for the new override:
    • override System.Windows.Forms.TrackBar.OnSizeChanged(System.EventArgs! e) -> void in PublicAPI.Unshipped.txt.

Customer Impact

  • The TrackBar UI control correctly reflects the properties.

Regression?

  • Yes

Risk

  • Mini

Screenshots

Before

image

After

14693.mp4
14693-1.mp4
14693-2.mp4

Test methodology

  • Manually

Test environment(s)

  • 11.0.0-preview.6.26317
Microsoft Reviewers: Open in CodeFlow

@SimonZhao888 SimonZhao888 marked this pull request as ready for review July 2, 2026 09:27
@SimonZhao888 SimonZhao888 requested a review from a team as a code owner July 2, 2026 09:27
@SimonZhao888 SimonZhao888 removed the draft draft PR label Jul 2, 2026

@LeafShi1 LeafShi1 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.

Thanks for the fix — the off-by-one in the tick loop is real and worth fixing. A few concerns to consider before merge:

  1. PR description vs. code mismatch. The description says "Override the OnSizeChanged() method...", but there is no OnSizeChanged/OnResize override in the diff. The resize scenario (issue #2 in #14693) actually appears to be fixed as a side effect of making the tick count size-independent (the native control rescales stored logical tick positions on resize). Please update the description to match the code, or clarify how the resize case is covered.

  2. No regression test. Since this is a runtime-only visual bug, please add a test asserting the tick count / last-interior-tick for the repro (Max=500, TickFrequency=50) so this doesn't regress again.

See inline comments for the specifics on the tick math.

Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Outdated
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Outdated

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

Fixes a regression in WinForms TrackBar tick rendering when falling back to the manual tick-rendering path, aiming to make drawn ticks consistently reflect TickFrequency across range/size changes.

Changes:

  • Adds validation/message resources for invalid TickFrequency values (rejects negatives; intends to allow 0).
  • Reworks DrawTicksManually() to compute tick positions deterministically and adjust drawing based on control size.
  • Adds localized resource entries for the new TickFrequency error string.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Updates TickFrequency validation and revises manual tick calculation/loop.
src/System.Windows.Forms/Resources/SR.resx Adds TrackBarTickFrequencyError string.
src/System.Windows.Forms/Resources/xlf/SR.cs.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.de.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.es.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.fr.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.it.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.ja.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.ko.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.pl.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.pt-BR.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.ru.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.tr.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.zh-Hans.xlf Adds localized entry for TrackBarTickFrequencyError.
src/System.Windows.Forms/Resources/xlf/SR.zh-Hant.xlf Adds localized entry for TrackBarTickFrequencyError.

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

Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Outdated
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Outdated
Comment thread src/System.Windows.Forms/System/Windows/Forms/Controls/TrackBar/TrackBar.cs Outdated
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.

TrackBar UI control doesn't reflect properties

3 participants