Is it possible for establish owner on new instance of forms?. While on Working with main form and model windows this question arise in my mind that suppose if I create a new instance of Form1 as below:
//this Instance From main window
CashDeposit cd=new CashDeposit();
cd.Show(this);
Now I am going to close the same and trying to make the new instance of the same on new EventHandller of the CashDeposit as below:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
this.Close();
CashDeposit cdd = new CashDeposit();
cdd.Show();
}
//this would showing without any owner but if I create the new instance on another way like below:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
this.Close();
CashDeposit cdd = new CashDeposit();
cdd.Show(this);
}
//than obviously it will going to fire the error like not creating owner on disposing object or control etc.
So It is hard for me to eastablish owner of new instance of CashDeposit from same class because the reference form is disposing and don’t know how to eastablish the new relation between both the main window form and CashDeposit from the Class of CashDeposit on new instance of the same.
Here the mainform is the owner of CashDeposit. And I am trying to eastablish owner on new instance of CashDeposit after the disposing the Old One(Relational) Form as above.
Any one have idea about how to achieve the same?.
Here I asked the question about establish the Main Form as a Owner into CashDeposit Class on New Instance of the same at certain EventHandller It may be Button Or TextboxKeyPress.
Look At Following Code:
The above Code In CashDeposit Class Eastblished as a Owner of a self Instance where as I want to Eastablish the main form as a onwer of CashDeposit on New Instance Hence I am prefere to go with below code which solved the matters.
Now As per above I just added Form.ActiveForm Property which shows the owner of the activeform and handle the Main Windows Form and Model Window Forms very well.