.Net Toolstrip / MenuStrip Focus Issues

Regardless of the scenario, I can fix this annoying problem 100% of the time. Create a .Net, C # or VB.Net project. Add a ToolStrip control to the form. Create some simple DropDownButton (s) that contain at least 2 menu items. Add any other controls you want to the list box (fill it up so it can receive focus correctly) and a ComboBox control. Either assign keyboard shortcuts or activate TabStop on the ToolStrip so that it can receive keyboard focus.

Run the project (Debug / Release that you ever liked). Use your keyboard to get the Focus ToolStrip Focus (by tab or shortcut key). Down arrow to sub. Now select the escape key to collapse the Toolstrip submenu. A tab in a ListBox or ComboBox that contains multiple items. Does everything look great? Now use the arrow keys to navigate these controls ... Surprise! your back on the ToolStrip and the controls you thought had no focus don't!

I tried a few things to get the focus on the ListBox. One example is adding an event handler for OnEnter (ListBox.Enter + = ...) and adding some code:

ListBox.Focus();
ListBox.Select(); 

      

Nothing worked ... It looks like as soon as the menu expands to the toolbar, you will be forever stuck on this control using your keyboard ... This is important for me to decide due to the fact that I work with blind users who use only keyboard navigation ... Is this a bug? I cannot reproduce this in MFC ...

Any suggestions?

Update I was able to find a control that doesn't reproduce this oddity ...

System.Windows.Forms.MainMenu is the only "toolbar object" that doesn't behave like the others ...

I would still like some feedback on this above (Help for others and myself) ...

Update 2 The main problem is with [ToolStripObject]. The .TabFocus property ... if set to false, everything seems to work fine ... giving focus back to the control that "looks" like it is focused. But having this ability to allow a blind user to navigate through all the UI controls through a tab is a handy thing to implement ... it's too bad that this property doesn't work as it should ...

+2


source to share


1 answer


I got it to work by overriding ToolStripMenuItem:



public class ToolStripMenuItemEx : ToolStripMenuItem {

  protected override bool ProcessCmdKey(ref Message m, Keys keyData) {
    if (keyData == Keys.Escape) {
      ToolStripDropDownButton tb = this.OwnerItem as ToolStripDropDownButton;
      if (tb != null) {
        tb.HideDropDown();
        return false;
      }
    }
    return base.ProcessCmdKey(ref m, keyData);
  }
}

      

+2


source







All Articles