+4  A: 

Because you call BackGroundColorArranger recursively with no exit condition. Here's a tip, when you get the stack overflow exception in the debugger, go to Debug Menu -> Windows -> Call Stack and you'll immediately see the problem.

Josh Einstein
A: 

You're getting a stack overflow because each of these calls each other (which then calls the other, and so on until the stack overflows):

Your code is effectively:

    void BackGroundColorArranger(Color, Color)
    {
        BackGroundColorArrangerBase(int);
    }
    void BackGroundColorArrangerBase(int)
    {
        BackGroundColorArranger(Color, Color);
    }
Rowland Shaw
A: 

You are recursively calling the same function, the stock overflow error means your recursion is never ending.

You need to change the parameters so that when the emthod calls itself it will eventually find an end.

ck
+2  A: 

Not being C# developer, it looks to me like you have a simple endless recursion there.

Is this a joke question or what's the deal here?

ypnos
A: 

As they have said you have an infinite recursive loop, and that's why you're getting the Stack Overflow.

As a quick fix remove this line from BackGroundColorArrangerBase:

BackGroundColorArranger(x, Color.FromArgb(z));

So it looks like this:

        void BackGroundColorArrangerBase(int z) 
        {
           Panel panel = new Panel();
           panel.ID = z.ToString(); //this wil generate the same id for the same pair of colors
           panel.Width = 150;
           panel.Height = 50;
           panel.BackColor = Color.FromArgb(z);
           this.Controls.Add(panel);
        }

That should stop the recursion. Its not very clear what you need beyond the dynamic panel creation. As is the code will just create one panel, and will create a new panel every time the BackGroundColorArranger is called -WITH A DIFFERENT COLOR PAIR- as you are using the colorpair as an ID for the panel.

If you need more than one panel make a finite loop calling BackGroundColorArranger with different pairs of colors ... if you need to actually see the panels on screen you'll need to change panel.Location of each in ArrangerBase, as now each panel starts at the origin with a fixed size.

Rostol