0

i have made a program, which include a lot of controls. The controls would be showed and hided according to the choice of the user. That means that controls overlapped on each other at design time. now i want to change the forecolor and backcolor of all controls at design time. but i founded so hard to accomplish this task, because all the control overlapping each other. so I decided to make a for loop method to iterate the controls in the form and then check each control in turn whether it has controls. when the control has also controls in it, I call the same method and pass the control to it to change the properties for the subcontrols too. The method like so:

void setColor(ref Control con)
        {
            con.BackColor= System.Drawing.Color.Black;
            con.ForeColor=System.Drawing.Color.Yellow;
            if (con.Controls.Count > 0) { setColor(ref con); }
        }

so my Form include tabControl with multiple tabPages. I iterate the tabPages and wanted to pass it to this method, but I become error "Indexer may not be passed as an out or ref parameter" I pass it so: setColor(ref tabControl1.Controls[i]);

can you please help me to solve this problem?

1 Answers1

0

I have resolved the problem. I have removed the "ref" from method and wrote the method simply like the following:

void SetColor(Control con)
    {
        con.BackColor = System.Drawing.Color.Black;
        con.ForeColor = System.Drawing.Color.Yellow;
        if (con.Controls.Count > 0)
        {
            for (int i=0; i<con.Controls.Count;i++)
            SetColor(con.Controls[i]);
        }
    }

and call it so: setColor(this.Controls[i]);