Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stack Overflow error on Color Changer Function

i have two color "red" also "Salmon". i need create dynamiclly panel also panel background color. These colors must be between two color(red

 public Color x, y;
        protected void Page_Load(object sender, EventArgs e)
        {
            BackGroundColorArranger(Color.Red, Color.Salmon);
        }
        void BackGroundColorArranger(Color x, Color y)
        {

            BackGroundColorArrangerBase(Convert.ToInt32((float)(x.ToArgb() + y.ToArgb()) / 2));
        }
        void BackGroundColorArrangerBase(int z)
        {
            Panel panel = new Panel();
            panel.ID = z.ToString();
            panel.Width = 150;
            panel.Height = 50;
            panel.BackColor = Color.FromArgb(z);
            this.Controls.Add(panel);
            BackGroundColorArranger(x, Color.FromArgb(z));
        }

But how can i do this. Above codes give me stackoverflow error.

like image 432
ALEXALEXIYEV Avatar asked May 26 '26 05:05

ALEXALEXIYEV


1 Answers

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.

like image 149
Josh Avatar answered May 30 '26 04:05

Josh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!