This question already has an answer here:
- Communicate between two windows forms in C# 12 answers
hey everyone I am currently trying to refresh a form once changes are done on a second. On my first form I press a button "create" that will open another form, form2. This second form will have input fields and allows you to input values that populate comboboxes on the first form. On the second form there is a button "update" I would like the fist form to refresh once update is pressed on the first.
I know there is this.refresh();
, but I'm not sure if this is useful for me. I am trying to something along the lines of:
On form2 -
Private void Form2UpdateButton_Click
{
//do update stuff
Form1_load.Refresh();
}
or maybe
private void Form2UpdateButton_Click
{
//do update stuff
Form1.close();
Form1.Open();
}
I am still pretty new to C# and interacting 2 forms together is a rather complex concept to me so please let me know if I am going about this the wrong way. My refresh may be in the wrong spot, but I think this is what I want.
Recommendations:
Your second form should be created with a reference to first one, ie,
Form1:
Form2:
One way is to pass a reference of Form1 to Form2, like this:
The above technique is called "Property-Injection";
Create an own event on form2 that triggers when the button gets clicked. This way you can just
form2.OnUpdateClicked += yourMethod
. Like this: