Skip to content

Use MouseWheel scrolling in ToolStripDropDownMenu #13303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

toehead2001
Copy link
Contributor

@toehead2001 toehead2001 commented Apr 14, 2025

Fixes #13302

Proposed changes

  • Add an OnMouseWheel override on ToolStripDropDownMenu to handle scrolling the menu items.

Customer Impact

  • Allow users to scroll a ToolStripDropDownMenu with the Mouse Wheel.

Regression?

  • No

Risk

  • Could potentially cause an issue if an application already has an override/event for handling MouseWheel on an ToolStripDropDownMenu.
  • Maybe need to add a property to make this opt-in or opt-out.

Test methodology

  • Manually tested through the user interface of scratch project.
Microsoft Reviewers: Open in CodeFlow

@Tanya-Solyanik
Copy link
Contributor

Error:
src\System.Windows.Forms\System\Windows\Forms\Controls\ToolStrips\ToolStripDropDownMenu.cs#L847

src\System.Windows.Forms\System\Windows\Forms\Controls\ToolStrips\ToolStripDropDownMenu.cs(847,29): error RS0016: (NETCORE_ENGINEERING_TELEMETRY=Build)
Symbol 'override System.Windows.Forms.ToolStripDropDownMenu.OnMouseWheel(System.Windows.Forms.MouseEventArgs! e) -> void'
is not part of the declared public API (https://github.com/dotnet/roslyn-analyzers/blob/main/src/PublicApiAnalyzers/PublicApiAnalyzers.Help.md)

Copy link

codecov bot commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 0% with 22 lines in your changes missing coverage. Please review.

Project coverage is 76.89944%. Comparing base (7c04597) to head (be95b05).

Additional details and impacted files
@@                 Coverage Diff                 @@
##                main      #13303         +/-   ##
===================================================
- Coverage   76.90689%   76.89944%   -0.00746%     
===================================================
  Files           3260        3260                 
  Lines         643088      643110         +22     
  Branches       47601       47605          +4     
===================================================
- Hits          494579      494548         -31     
- Misses        144845      144893         +48     
- Partials        3664        3669          +5     
Flag Coverage Δ
Debug 76.89944% <0.00000%> (-0.00746%) ⬇️
integration 18.97564% <0.00000%> (-0.01227%) ⬇️
production 51.56089% <0.00000%> (-0.01472%) ⬇️
test 97.42152% <ø> (ø)
unit 48.95130% <0.00000%> (-0.00826%) ⬇️

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@Copilot Copilot AI left a comment

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 adds support for scrolling a ToolStripDropDownMenu using the mouse wheel, addressing issue #13302.

  • Implements an override of OnMouseWheel in ToolStripDropDownMenu to calculate and apply a scroll amount.
  • Updates PublicAPI.Unshipped.txt to document the new override.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDownMenu.cs Added OnMouseWheel override handling scroll logic.
src/System.Windows.Forms/PublicAPI.Unshipped.txt Added API declaration for the new override.
Comments suppressed due to low confidence (1)

src/System.Windows.Forms/System/Windows/Forms/Controls/ToolStrips/ToolStripDropDownMenu.cs:865

  • [nitpick] Consider renaming 'delta' to 'scrollDelta' to clarify that it represents the scroll amount calculated from the mouse wheel event.
int delta = firstItemBounds.Height * SystemInformation.MouseWheelScrollLines * -Math.Sign(e.Delta);

@Tanya-Solyanik Tanya-Solyanik added the waiting-author-feedback The team requires more information from the author label Apr 16, 2025
@toehead2001 toehead2001 force-pushed the ToolStripDropDownMenu-MouseWheel-Scroll branch from f1ad6c1 to bf72ef2 Compare April 16, 2025 04:32
@Tanya-Solyanik
Copy link
Contributor

System.Windows.Forms.Tests.ClipboardTests.SetDataObject_InvokeObjectBoolNotIComDataObject_GetReturnsExpected(data: "data", copy: True)

Error message
Expected object to be "data", but found "".

Stack trace
at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
at FluentAssertions.Execution.AssertionChain.FailWith(Func1 getFailureReason) at FluentAssertions.Primitives.ObjectAssertions2.Be(TSubject expected, String because, Object[] becauseArgs)
at System.Windows.Forms.Tests.ClipboardTests.SetDataObject_InvokeObjectBoolNotIComDataObject_GetReturnsExpected(Object data, Boolean copy) in /_/src/test/unit/System.Windows.Forms/System/Windows/Forms/ClipboardTests.cs:line 307
at InvokeStub_ClipboardTests.SetDataObject_InvokeObjectBoolNotIComDataObject_GetReturnsExpected(Object, Span`1)
at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

@toehead2001
Copy link
Contributor Author

That error looks unrelated to the code changes in this PR.

@Tanya-Solyanik
Copy link
Contributor

That error looks unrelated to the code changes in this PR.

@toehead2001 - I'm adding these errors for our internal tracking. ClipboardTests is a known flaky set of tests because they read from a machine-wide resource, we ignore any non-recurring failures there.


protected override void OnMouseWheel(MouseEventArgs e)
{
base.OnMouseWheel(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please explain why the base class handling in insufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The direct base class (ToolStripDropDown) doesn't have a implementation of OnMouseWheel, so what gets called here is the implementation all the way down in ScrollableControl.
Obviously, ScrollableControl doesn't know how to handle the re-positioning of ToolStripItems, and just handles normal Controls.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right, but why does scrollable control need to know about the ToolStripItems. Is ClientRectangle or Display rectangle calculated incorrectly in this case?

Copy link
Contributor Author

@toehead2001 toehead2001 Jul 21, 2025

Choose a reason for hiding this comment

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

The parent ToolStrip class has it own scroll implementation that doesn't use OnScroll() of ScrollableControl.

internal virtual void ScrollInternal(int delta)

I am not sure why it was originally designed that way.

@toehead2001 toehead2001 force-pushed the ToolStripDropDownMenu-MouseWheel-Scroll branch from b2b133d to be95b05 Compare July 21, 2025 04:23
@dotnet-policy-service dotnet-policy-service bot removed the waiting-author-feedback The team requires more information from the author label Jul 21, 2025
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.

Utilize Mouse Wheel for scrolling in ToolStripDropDownMenu
2 participants