I have 3 winforms in my project and on Form3 there is a checkbox. What I want to be able to do is to click this checkbox, then when the form is exited make the same check (whether checked or not) on the one in Form1. The existing code I have is follows, but it just won’t work, am I missing a trick somewhere? Thanks.
//Form3
Form1 setDateBox = new Form1();
setDateBox.setNoDate(checkBox1.Checked);
//Form1
public void setNoDate(bool isChecked)
{
checkBox1.Checked = isChecked;
}
A couple of approaches:
1 – Store the Form1 variable “setDateBox” as a class member of Form3 and then access the “setNoDate” method from the checkboxes CheckedChanged event handler:
2 – If you do not wish to store setDateBox as a class member or you need to update more than one form, you could Define an event within Form3 which like so:
Create a handler for the event in Form1:
Assign the event handler after creating the form:
And then fire the event from Form3 (upon the checkbox’s checked state changing):
Hope this helps.