-2

Hello for everyone I am new here,sorry if this post doens't match with at all with how should be,because It's my first post this.

I am wanting to change the value of the Label when I choose one CheckBox,but It's seems that the Label just changes when I click in the Label. I was looking for see if the Label had some Events for make work it but I didn't found one. The Label it's in another groupBox,It's seems like that :

In one GroupBox has 3 CheckBox and i want that when i choosing one or all from that CheckBox will change the value of the Label in the another GroupBox.

Please guys,help me here,I am really wanting to understand why It's not working.

Falion
  • 247
  • 1
  • 11
  • 1
    Subscribe to Checkbox_CheckedEvent and do the operation and update the other label. – sumeet kumar Aug 31 '15 at 20:37
  • 1
    save your self the headache as well as other asking.. and post your code that you have thus far so that we can see where you doing something incorrectly if that.. – MethodMan Aug 31 '15 at 20:38
  • I just don't post the code because It's in Brazilian Portuguese and I think you guys will not understand. – Falion Aug 31 '15 at 20:41
  • there is a thing called Google Translate if you need to trans late the code we need to see what it is that you are trying to do when you check a checkbox it's either going to set the Label.Text = to something or it's not – MethodMan Aug 31 '15 at 20:42
  • private void chkConsulta_CheckedChanged(object sender, EventArgs e) { if (chkConsulta.Checked == true) { lblConsulta.Text = "R$ 75.00"; } if (chkConsulta.Checked == false) { lblConsulta.Text = "R$ 0.00"; } } – Falion Aug 31 '15 at 20:51
  • I am trying to make It's change if true when I choose this CheckBox(chkConsulta) but it won't work at all,the Label doens't change,just if I click in the Label will change,and I want to the Label change when choosing one of the three CheckBox. – Falion Aug 31 '15 at 20:54

2 Answers2

2

You can just register an event handler for the CheckChanged event and change the label's caption in the event handler :

public partial class Form1 : Form
{
    public MyForm()
    {
        InitializeComponent();
        myCheckbox.CheckedChanged += new System.EventHandler(this.checkedChanged);
        myCheckbox1.CheckedChanged += new System.EventHandler(this.checkedChanged);
        myCheckbox2.CheckedChanged += new System.EventHandler(this.checkedChanged);


    }

    private void checkedChanged(object sender, EventArgs e)
    {
        myLabel.Text = "Some text";
    }
}
Black0ut
  • 1,642
  • 14
  • 28
0

use this code here, but change the event to the control you're looking for

private void radioButton1_CheckedChanged(object sender, EventArgs e)
    {
        label1.Text = "your value here";
    }

you can do this by double clicking on the radio button control and then it will generate the event for you and then set your code as per the example here.

Simon Price
  • 3,011
  • 3
  • 34
  • 98