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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With