繁体   English   中英

清除特定的标签页文本框

[英]Clear specific tabpage text boxes

我的tabcontrol页面中有4个标签。 我想清除最后一个标签中的所有文本框。 但是我使用的代码仅清除所选的texbox。

foreach (Control control in tabcontrol1.SelectedTab.Controls)
{
    TextBox text = control as TextBox;
    if (text != null)
    {
        text.Text = string.Empty;
    }
}

因此,您想在最后一个标签中找到所有文本框吗? 您可以使用htis:

var allTxt = tabcontrol1.TabPages.Cast<TabPage>().Last().Controls.OfType<TextBox>();

foreach(TextBox txt in allTxt)
    txt.Text = "";

(您需要using System.Linq添加)

尝试一下:可能对您有用。

void ClearTextBoxes(Control parent)
    {
        foreach (Control child in parent.Controls)
        {
            TextBox textBox = child as TextBox;
            if (textBox == null)
                ClearTextBoxes(child);
            else
                textBox.Text = string.Empty;
        }
    }

    private void resetCurrentPageToolStripMenuItem_Click(object sender, EventArgs e)
    {
        ClearTextBoxes(tabControl1.SelectedTab);
    }

请访问以下链接。 您将获得有关如何使用清晰控件的更好的解释。 用一个Function清除所有形式的文本框 希望对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM