WinForm的 - 接受tab不工作 [英] WinForm - TabStop Not Working

查看:132
本文介绍了WinForm的 - 接受tab不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3组框,其中一个组合框和两个单选按钮一个WinForm。我把所有的人及其子女的控制,以接受tab =假,但是当我周期,TAB,在每个最后两个组框被关注当前选定的单选按钮。



如果没有办法改变这种行为,这将是一个很好的事件捕获和移动焦点了吗?我无法找到一个聚焦状态事件。






解决的办法是设置一个方法(下面的代码)来处理在表格的Enter每一个单选按钮的事件(如果那是你希望的东西)。



其实,我只做到了第一组框单选按钮和它的工作,第二组框的单选按钮没有得到关注,即使他们的回车事件不处理。这是不是你本来期望的行为。

 私人无效radiobuttonXGroup1_Enter(对象发件人,EventArgs五)
{
SomeOtherControl.Focus();
}

在*了.Designer.cs文件编辑每一个输入事件(每单选按钮)为指向一个事件处理程序(上面的方法)。

  this.radiobutton1Group1.Enter + =新System.EventHandler (this.radiobuttonXGroup1_Enter); 
this.radiobutton2Group1.Enter + =新System.EventHandler(this.radiobuttonXGroup1_Enter);
this.radiobutton3Group1.Enter + =新System.EventHandler(this.radiobuttonXGroup1_Enter);


解决方案

MSDN文档的RadioButton.TabStop 指出:此API支持.NET Framework基础结构,不适合直接在代码中使用。这基本上意味着,这是行不通的,你如何指望它。



随着中说,Enter事件会当按钮接收焦点开火。您可以尝试使用移动焦点到另一个控件。


I have a WinForm with 3 group boxes, one with combo boxes, and two with radio buttons. I set all of them and their children controls to "TabStop = false", but when I cycle with TAB, the currently selected radio button in each of the last two group boxes gets focused.

If there's no way to change this behavior, what would be a good event to catch and move the focus away? I can't find an "OnFocus" event.


The solution is to set one method (code below) to handle the "Enter" event of every radio button in the form (if that's what you wish).

Actually, I only did it for the radio buttons of the first group box and it worked, the second group box's radio buttons don't get focus, even though their "Enter" events are not handled. This is not the behavior you would have expected.

private void radiobuttonXGroup1_Enter(object sender, EventArgs e)
{
   SomeOtherControl.Focus();
}

In the *.Designer.cs file you edit every Enter event (for each radio button) to point to one event handler (the above method).

this.radiobutton1Group1.Enter += new System.EventHandler(this.radiobuttonXGroup1_Enter);
this.radiobutton2Group1.Enter += new System.EventHandler(this.radiobuttonXGroup1_Enter);
this.radiobutton3Group1.Enter += new System.EventHandler(this.radiobuttonXGroup1_Enter);

解决方案

The MSDN documentation for RadioButton.TabStop states "This API supports the .NET Framework infrastructure and is not intended to be used directly from your code". Which basically means, "This isn't going to work how you expect it to".

With that said, the Enter event will fire when the button receives the focus. You can try to use that to move focus to another control.

这篇关于WinForm的 - 接受tab不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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