-->

用单选按钮C#标签顺序(C# tab order with radio buttons)

2019-09-23 15:21发布

所以我有一个Windows窗体应用程序,有你想选择什么食品项目,它告诉你一个文本框。 有三个单选按钮的答案,您可以从选择和提出,答案的按钮。 我要的是能够通过使用标签的单选按钮来浏览。 我曾尝试Tab顺序的事情,但它不工作。 有什么建议么?

Answer 1:

WINDWS形式可以让你只选项卡进组。 破解它周围的一种方法是通过将它们中的每一个周围组框获得单独组中的所有按钮。

虽然这可以让你通过选项卡他们,他们现在是脱节的,并不会自动取消。 为此注册上选择触发事件和编程取消选择其他。

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {

        private List<RadioButton> allMyButtons;

        public Form1()
        {
            InitializeComponent();
            allMyButtons = new List<RadioButton>
            {
                radioButton1,
                radioButton2
            };
        }

        private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton sendingRadio = (sender as RadioButton);
            if(sendingRadio == null) return;
            if(sendingRadio.Checked == true){
                foreach(var rb in (from b in allMyButtons where b != sendingRadio select b))
                {
                    rb.Checked = false;
                }
            }
        }

    }
}

我测试了这种方法,它似乎做的工作。

形式是不做事的现代生活方式。 考虑迁移到WPF的新项目。



文章来源: C# tab order with radio buttons