Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Radu - Adrian Buha
PLUS
Radu - Adrian Buha
Courses Plus Student 5,535 Points

Simple C# Windows Form App with 3 radio buttons and one label won't work.

Hello.

I have a problem with a concept. I have a simple C# Windows Forms App with 3 radio buttons and one label. All I want is for the label to change its value when I click on a different radio button. I have tried the following code, but it doesn't work. I have tried searching on an answer on the web but i didn't find anything that would work. Can anyone help me?

The code: public partial class Form1 : Form { public Form1() { InitializeComponent(); }

    private void radioButton1_EnabledChanged(object sender, EventArgs e)
    {

        SetLabelValue("Joe");

    }

    private void radioButton2_EnabledChanged(object sender, EventArgs e)
    {

        SetLabelValue("Bob");

    }

    private void radioButton3_EnabledChanged(object sender, EventArgs e)
    {

        SetLabelValue("Al");

    }

    private void SetLabelValue(string Name)
    {
        label1.Text = Name;
    }
}

1 Answer

Steven Parker
Steven Parker
231,271 Points

It doesn't look like "label1" (in the method "SetLabelValue") is ever defined or assigned.