繁体   English   中英

如何清除WinForm中的所有SpellBox控件

[英]How to clear all SpellBox controls in WinForm

我有一个WinForm项目,该项目利用了WPF SpellBoxes 我现在正在创建一个函数来清除我的所有字段以及该类中的TextBoxes。 textBoxes实际上是SpellBoxes集成到项目中,这就是为什么我认为我遇到了这个问题。 以我的理解,这将是通过以下所有循环遍历所有控件的最佳方式:

public void ClearControls()
        {
            foreach (Control control in panel1.Controls)
            {
                if (control is SpellBox)
                {
                    SpellBox txt = (SpellBox)control;
                    txt.Text = "";
                }


            }
        }

然后在点击事件中调用ClearControls();

但是由于我使用SpellBoxes,我似乎甚至无法遍历,就好像它们甚至未被识别。 上面的函数适用于TextBox的,但不适用于spellBox's 如果有人能告诉我为什么会这样,我将不胜感激。 提前致谢

递归搜索的快速示例:

public void ClearControls(Control cntr)
{
    foreach (Control control in cntr.Controls)
    {
        if (control is SpellBox)
        {
            control.Text = "";
        }
        else if(control.HasChildren)
        {
            ClearControls(control);
        }
    }
}

您可以通过经由窗体本身传递开始它关闭this

ClearControls(this);

暂无
暂无

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

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