如何在不选择的情况下浏览 Windows 窗体中的 RadioButton 组

编程入门 行业动态 更新时间:2024-10-28 21:14:36
本文介绍了如何在不选择的情况下浏览 Windows 窗体中的 RadioButton 组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个包含一堆控件的 Windows 窗体 GUI,其中一个是包含一组 RadioButton 的 FlowLayoutPanel.

I have a Windows Forms GUI that has a bunch of controls, one of which is a FlowLayoutPanel containing a group of RadioButtons.

我可以使用 Tab 键切换到第一个 RadioButton(TabIndex 和 TabStop 设置正确),但是当我再次点击 Tab 键时,它会将我带到表单上的下一个控件,而不是 FlowLayoutPanel 中的下一个单选按钮.

I can tab to the first RadioButton (TabIndex and TabStop set properly), but when I hit tab again it takes me to the next control on the form, not the next radio button in the FlowLayoutPanel.

一旦第一个 RadioButton 获得焦点,通过该组的唯一方法是使用向上/向下箭头,但这实际上是选择 RadioButton.选择 RadioButton 会启动一些其他的东西,所以我只想找到一种方法来浏览列表以找出要选择的内容.

Once the first RadioButton has focus, the only way to go through the group is to use up/down arrows, but that actually selects the RadioButton. Selecting a RadioButton kicks off some other stuff, so I just want a way to tab through the list to figure out what to select.

理想情况下,我想要的是让每个 RadioButton 像页面上的任何其他控件一样运行,并允许我在不选择 RadioButton 的情况下浏览整个组,直到我点击 Space.

What I want, ideally, is to have each RadioButton act like any other control on the page and allow me to tab through the whole group without selecting a RadioButton until I hit Space.

推荐答案

此 Tab 键顺序是默认的 Windows 行为,很少有好的做法进行更改.

This tab order is default Windows behaviour and it is rarely good practice to change this.

这是因为组中的单选按钮让 TabStop 以这种方式工作.

It happens as the Radio Buttons in a group have TabStop juggled to work this way.

要更改此设置,请在每次重置时将 Tab Stop 显式设置为 true:

To change this, explicitly set the Tab Stop to true every time it is reset:

public Form1() { InitializeComponent(); foreach (var control in this.flowLayoutPanel1.Controls.OfType<RadioButton>()) { control.GotFocus += (s,a) => SetTabStops(flowLayoutPanel1); control.CheckedChanged+= (s,a) => SetTabStops(flowLayoutPanel1); } } private static void SetTabStops(Control host) { foreach (Control control in host.Controls) { control.TabStop = true; } }

更多推荐

如何在不选择的情况下浏览 Windows 窗体中的 RadioButton 组

本文发布于:2023-11-04 21:42:56,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559088.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗体   情况下   如何在   Windows   RadioButton

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!