ie:
parent :
public int a=0;
parent_Load()
{
child.MdiParent=this;
child.show();
}
Child :
button1_Click()
{
parent p=new parent();
p.a=1;
this.close();
}
but the problem is; when the focus returns to parent, the value of a remains the same(0).
pls help...
NainilPosted Mar 2, 2010, 3:50 PM
In the button1_Click() event, when you instantiate a parent object, what it's doing is it is creating a new parent object. It has nothing to do with the MDI child's MDI parent. To get a reference to the MDI parent you should use the this.ParentForm property and cast it to the parent class. So for example if your parent class is called Parent, then the button1_Click() function should be as follows:
button1_Click()
{
Parent oParent = (Parent) this.ParentForm;
oParent.a = 1;
this.Close();
}
After doing this when the focus returns to the parent, the value of the variable will be changed. Hope this helps.