You have to use the current object of your frmForm class and not to create a new one, so in order to communicate between two forms objects you should do the next steps:
1.Your main form
fromMain
class have to implement an
interface
like the next one:
public interface IMyForm
{
void PerformRefresh();
}
class frmMain : Form, IMyForm
{
}
2.Then in the Form2 class add a property of type IMyForm and use it in Close event:
class Form2 : Form
{
public IMyForm MainForm{get;set;}
private void btnClose_Click(object sender, EventArgs e)
{
if (strmode == "strnew")
{
this.MainForm.PerformRefresh();
}
}
}
3.Finally in your main form when the
Form2
object is created you must set its new property like below:
private void btnNew_Click(object sender, EventArgs e)
{
Form2 frm = new Form2();
frm.MainForm = this;
frm.Show();
}