.Net Toolstrip / MenuStrip焦点问题 [英] .Net Toolstrip/MenuStrip Focus Issues

查看:258
本文介绍了.Net Toolstrip / MenuStrip焦点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不管情况如何,我都可以在100%的时间内重新创建这个烦人的问题。
创建一个.Net项目,C#或VB.Net。将一个ToolStrip控件添加到窗体。创建一个包含至少两个菜单项的简单DropDownButton(s)。添加你想要的任何其他控件,一个列表框(填充它,以便它可以正确接收焦点)和一个组合框控件。分配快捷键或在ToolStrip上启用TabStop,以便通过键盘获得焦点。



运行项目(调试/释放,这是你想象的)。使用键盘给ToolStrip焦点(通过标签或快捷键)。向下箭头进入子项目。现在选择退出键折叠Toolstrip子菜单。选项卡到包含几个项目的列表框或组合框。
所有看起来不错的权利?现在使用箭头键在这些控件中导航...惊喜!你在ToolStrip上的背部和你认为有焦点的控件不是!

我已经尝试了多种方法来强制对ListBox进行操作。一个例子是我添加事件处理程序的OnEnter(ListBox.Enter + = ...),并添加一些代码,如:

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

没有什么是成功的......看起来好像一旦菜单在工具条上展开,您将永远停留在这个控制使用您的键盘...
这对我来说是重要的解决,因为我的盲人用户使用键盘导航的唯一工作...这是一个错误?

有什么建议吗?
$ b $ p

更新

/ em>
我能够找到一个不会重现这种奇怪的控制...
$ b $ System.Windows.Forms.MainMenu是唯一的工具栏对象,不像其他人... ...

我仍然喜欢上面的一些反馈(帮助别人和我自己)...
$ b

更新2
根本问题是[ToolStripObject] .TabFocus属性...如果设置为false,似乎所有工作都可以正常进行......将注意力集中到看起来像是关注的控件上。但有这样的能力,让盲人用户浏览所有UI控件通过标签是一个方便的事情来实现...这太糟糕了,这个属性不能像它应该工作....

 

> public class ToolStripMenuItemEx:ToolStripMenuItem {

protected override bool ProcessCmdKey(ref Message m,Keys keyData){$ b $ if(keyData == Keys.Escape){
ToolStripDropDownButton tb = this .OwnerItem作为ToolStripDropDownButton;
if(tb!= null){
tb.HideDropDown();
返回false;
}
}
返回base.ProcessCmdKey(ref m,keyData);
}
}


No matter what the scenario may be I'm able to recreate this annoying problem 100% of the time. Create a .Net project, C# or VB.Net. Add a ToolStrip control to the form. Create a few simple DropDownButton(s) that contain at least 2 menu items. Add any other controls you wish, a list box (populate it so it can receive focus correctly) and a ComboBox control. Either assign shortcut keys or enable TabStop on the ToolStrip so that it can receive focus by Keyboard.

Run the project (Debug/Release, which ever you fancy). Use your Keyboard to give the ToolStrip Focus (by tab or shortcut key). Arrow down into a sub item. Now select the escape key to collapse the Toolstrip sub menu. Tab to the ListBox or ComboBox that contains a few Items. All looks great right? Now use your arrow keys to navigate in these controls... Surprise! your back on the ToolStrip and the control you thought had focus doesn't!

I've tried multiple things to force focus on the ListBox. One example is I'd add the event handler for OnEnter (ListBox.Enter+=...) and add some code like:

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

Nothing was a success... It seems like once the menu expands on a toolstrip you will be forever stuck on this control using your Keyboard... This is important for me to resolve due to the fact that i work with blind users whom use keyboard navigation only... 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 strangeness...

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

I'd still like some feedback on the above though (Help for others and myself)...

Update 2 The underlying issue is within [ToolStripObject].TabFocus property... if set to false all seems to work ok... giving focus back to the control that "looks" like it's focused. But having that capability to allow a blind user to navigate throughout all UI controls via tab is a handy thing to implement... it's too bad this property doesn't work like it should....

解决方案

I got it to work by overriding the 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);
  }
}

这篇关于.Net Toolstrip / MenuStrip焦点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆