Tag: 嵌套控件

控制WinForms中的嵌套限制

我正在运行时创建表单的控件,出于某种原因,我需要深度超过49个嵌套控件(即控件包含在另一个控件中)。 但出现以下错误: 如何添加彼此嵌套的更多控件? 这是一段可能重现错误的代码: public partial class Form1 : Form { public Form1() { InitializeComponent(); Panel lastPanel = panel1; for (int i = 0; i < 49; i++) { Console.WriteLine(i); Panel newPanel = new Panel(); lastPanel.Controls.Add(newPanel); lastPanel = newPanel; } } }