在换色功能堆栈溢出错误

在换色功能堆栈溢出错误

本文介绍了在换色功能堆栈溢出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个颜色的红也是鲑鱼。我需要创建dynamiclly面板还面板的背景颜色。这些颜色必须是两种颜色(红色之间

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

但我怎么能做到这一点。以上codeS给我的计算器错误。

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

推荐答案

正如他们说你有一个无限递归循环,这就是为什么你得到的堆栈溢出。

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

作为一个快速修复删除此行从BackGroundColorArrangerBase:

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

这应该停止递归。它不是很清楚你所需要超越的动态面板创建。由于是code将只创建一个面板,并且每次BackGroundColorArranger被调用时会创建一个新的面板 - 随着你使用的是colorpair作为面板的ID不同的颜色PAIR-。

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.

如果你需要一个以上的面板做的有限的循环调用BackGroundColorArranger与对不同颜色的......如果你需要真正看到屏幕上的面板,您需要更改panel.Location每个在ArrangerBase的,因为现在的每个面板开始于具有固定大小的原点。

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.

这篇关于在换色功能堆栈溢出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 05:46