-
Notifications
You must be signed in to change notification settings - Fork 954
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
[API Proposal]: add ToolStripItem.SelectedChanged event #8548
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Looks good as proposed namespace System.Windows.Forms
{
public partial class ToolStripItem
{
public event EventHandler? SelectedChanged;
protected virtual void OnSelectedChanged(EventArgs e);
}
} |
Tested the fix in the latest .Net 9.0 SDK build: 9.0.100-alpha.1.23618.4, when using keyboard to focus or leave toolStripMenuItem, the SelectedChanged event is invoked once, but when using mouse to focus, the SelectedChanged event is invoked twice. @Epica3055 could you please look at it if the behavior is expected? SelectedChanged_Test.mp4 |
@Tanya-Solyanik hi, I need to discuss this with you. In framework, The question is what is expected behavior in .Net? In the issue description, But that's not the case in Framework. |
@Epica3055 - what you are saying about symmetric behavior makes sense, if we were implementing a completely new event, we would had raised it in both cases - Selected->Unselected and Unselected -> Selected. However, the purpose of this implementation is to simplify migration from .NET Framework, so we should implement the same behaviour as the .NET Framework has. |
Closing issue as the PR and follow up have been merged. |
Background and motivation
This is a follow-up to #3572
.NET Core 3.1 introduced a breaking change in using Menus. MenuItem control was removed and ToolStripMenuItem is recommended as a replacement.
However, the new ToolStripMenuItem class is missing the equivalent to MenuItem's Select event, that fires when menu item is highlighted by mouse or keyboard.
This event is most commonly used to display hints/descriptions/feedback to user when they navigate through menu items.
Some workarounds are the following ToolStripMenuItem's events:
MouseEnter
,MouseLeave
,MouseHover
, etc. But this does not cover the selection of a ToolStripMenuItem via keyboard (e.g. arrow keys).Adding a new
SelectedChanged
event to the ToolStripItem class could be a solution to the problem. The event fires every time the Selected property value changes, similar to AvailableChanged or EnabledChanged events.API Proposal
API Usage
Here the SelectedChanged event is used to show a hint whenever user selects menu item with mouse or keyboard:
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: