Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return a value from checkbox_CheckChanged

How can I get a value returned from the checkbox_CheckChanged event please? Its a winforms app, and both the form and the checkbox are created programmatically. Thanks for all and any help.

like image 663
user995689 Avatar asked Oct 24 '25 01:10

user995689


1 Answers

The Controls event handlers are always "void" and you cant change the return type. Instead you can take an external variable and you change that value only in when the CheckedChanged Event occurs.

public bool checkedthecheckbox { get; set; }

CheckBox testchbox = new CheckBox();

private void Form1_Load(object sender, EventArgs e)
{
    testchbox.CheckedChanged += new EventHandler(testchbox_CheckedChanged);
}

void testchbox_CheckedChanged(object sender, EventArgs e)
{
    if (testchbox.Checked)
        checkedthecheckbox = true;
    else
        checkedthecheckbox = false;
}
like image 166
Sai Kalyan Kumar Akshinthala Avatar answered Oct 26 '25 00:10

Sai Kalyan Kumar Akshinthala



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!