hi :)
This is my code:

public static void ChangeColor(string myObject, string myColor)
        {
            myObject.ForeColor = Color.myColor; //This doesnt work, why?
        } 

private void button1_Click(object sender, EventArgs e)
        {
            ChangeColor("Programming", "PowderBlue");
        }

"Programming" is a label

I've written many programs in VB but i'm new to C# so I don't really know how it works :S

Thanks in advance!

try this

public static void ChangeColor(Label myObject, Color myColor)
        {
            myObject.ForeColor = myColor; 
        } 

        private void button1_Click(object sender, EventArgs e)
        {
            ChangeColor(label1, Color.PowderBlue);
             
        }

Hey thanks! Works perfectly :)

mark as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.