簡體   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