尝试从组框中删除控件时出现 C# 奇怪的错误

C# Weird Bug when trying to remove Controls from Group Box

我目前面临一个非常奇怪的问题。我只是想从组框中删除所有控件,但它并没有删除所有控件。它现在看起来真的像是微软端的一个错误。我尝试了许多不同的方法来删除这些控件,但其中 none 有效。我有另外两种方法,一次只删除一个控件(不,我不能在所有控件的循环中调用它)并且它工作正常。我不知道可能是什么问题。希望有人知道解决这个问题的方法。

foreach (Control c in fieldBox.Controls) // this does not work, it only removes my labels (I have one txt and one lbl)
                fieldBox.Controls.Remove(c);

            for (int i = 0; i < fieldBox.Controls.Count; i++) // this does not work either
                fieldBox.Controls.Remove(fieldBox.Controls[i]);

            for (int i = 0; i < fieldBox.Controls.Count; i++) // still no success
                fieldBox.Controls.RemoveAt(i);

            for (int i = 0; i < fieldBox.Controls.Count; i++) // nope
                fieldBox.Controls.RemoveByKey(fieldBox.Controls[i].Name);

            foreach (Control c in fieldBox.Controls) // my final answer, but the outcome did not change
                fieldBox.Controls.RemoveByKey(c.Name);

尝试减少计数器并删除控件

for (int i = fieldBox.Controls.Count - 1; i >= 0; i--) // hopefully successful
            fieldBox.Controls.RemoveAt(i);