控制嵌套限制中的WinForms嵌套、WinForms

2023-09-05 00:38:03 作者:垂泪话凄凉

我在运行时创建我的窗体的控件,出于某种原因,我需要的深度超过49嵌套控件(即控件包含在另一个)。

但出现以下错误:

如何添加嵌套在对方更多的控制?

下面是一小片code,可能会重现该错误:

 公共部分类Form1中:形态
{
    公共Form1中()
    {
        的InitializeComponent();

        面板lastPanel = PANEL1;
        的for(int i = 0; I< 49;我++)
        {
            Console.WriteLine(ⅰ);
            面板newPanel =新面板();
            lastPanel.Controls.Add(newPanel);
            lastPanel = newPanel;
        }
    }
}
 

解决方案

据的雷蒙德陈,你不能的,这是对的窗户行政开发商经过深思熟虑选择。

资管新规 过渡期倒计时3个月

I'm creating my form's controls in the runtime, and for some reason, I need the depth to be more than 49 nested controls (i.e. control is contained in another one).

but the following error appears:

How can I add more controls nested in each other ?

Here is a little piece of code that may reproduce the error:

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;
        }
    }
}

解决方案

According to Raymond Chen you cannot, it was a deliberate decision on the part of the windows executive developers.