本文介绍了选择不同tabcontrol上的radiobuttons的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述













您好

Hi

我有一个winforms应用程序我C#witch有一个tabcontrol有3个标签。每个标签有4个radiobuttons。如果我运行应用程序,单选按钮在同一选项卡中正常工作,但当我选择另一个选项卡时,选择仍保留在第一个选项卡中。我试图在更改标签时清除所有已检查的
radiobuttons但由于某种原因它不起作用。

所有单选按钮都与设计师一起添加到每个标签页。

代码使用的是:

I have a winforms app i C# witch has a tabcontrol with 3 tabs. Each tab has 4 radiobuttons. If i run the app, the radio buttons work fine within the same tab, but when i select another tab the selection remains in the first tab. I tried to clear all checked radiobuttons when changing tabs but for some reason it does not work.
All radiobuttons were added to each tabpage with the designer.
The code is use is:

private void UncheckLayouts(TabPage activePage)
{
    foreach (Control control in tabControl1.Controls)
    {
        if (control is RadioButton)
        {
            RadioButton rb = control as RadioButton;
            rb.Checked = false;
        }
    }
}

private void radioButton1_Click(object sender, EventArgs e)
{
    UncheckLayouts(tabControl1.SelectedTab);
}

private void radioButton2_Click(object sender, EventArgs e)
{
    UncheckLayouts(tabControl1.SelectedTab);
}
...

我也尝试过这样:

private void tabControl1_Deselecting(object sender, TabControlCancelEventArgs e) {
    foreach (var ctrl in e.TabPage.Controls) {
         if (ctrl is RadioButton) {
             RadioButton tb = ctrl as RadioButton;
             rb.Checked = false;
         }
    }
}

并尝试这样做:

public Form2()
{
    InitializeComponent();
    tabControl1.Selected += TabControl1_Selected;
}
private void TabControl1_Selected(object sender, TabControlCancelEventArgs e)
{
    foreach (var ctrl in e.TabPage.Controls)
    {
        if (ctrl is RadioButton)
        {
            RadioButton tb = ctrl as RadioButton;
            tb.Checked = false;
        }
    }
}

但没有解决方案可行。

But no solution works.

任何人都可以帮忙。在此先感谢,

Can anyone help please. Thanks in advance,

推荐答案

单选按钮是单个选项的构造在一个组中,总是需要检查一个
按钮。

Radio buttons are a construct for a single choice in a group, one
button is always expected to be checked.

您是否需要复选框?

戴夫


这篇关于选择不同tabcontrol上的radiobuttons的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 04:08