Q:

How could i change the Text of an label by a function?

I have a Label on my Windows Forms, and I want to change the Text of it by a Button2_Click, but only if an another Button clicked before.
Example Code:
bool var1 = false;
//the Label Example
label1.Text = "Noooh!";

private void Button2_Click(object sender, EventArgs e)
{
    function1(label1.Text);
}

private void Button1_Click(object sender, EventArgs e)
{
    var1 = true;
}

private void function1(string Text)
{
    if (var1)
    {
        Text = "Yeaaah!";
    }
}

It should work like this, you need to click on the button1 first, after this you should click button2 by this the function1 should be activated and change the label1 Text to "Yeaaah!". The Code is executed in Visual Studio but the label1 Text doesn't change, don't know why.

A:

Change function's (techically, we call it method, not function) design, pass Control (e.g. label1), not its Text:
private void Button2_Click(object sender, EventArgs e)
{
    // we modify control...
    function1(label1);
}

private void function1(Control ctrl)
{
    if (var1)
    {
        // ... control's Text to be exact
        ctrl.Text = "Yeaaah!";
    }
}

