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:

Exception

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;
        }
    }
}
user2302005
  • 227
  • 1
  • 2
  • 7

1 Answers1

6

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

Mgetz
  • 5,108
  • 2
  • 33
  • 51
  • Thank you for the confirmation. I have encountered this exact issue in one component of our company's application. – KyleK Feb 05 '14 at 22:37