Want to call a method before visible=true for a form

  • Thread starter Thread starter tony
  • Start date Start date
T

tony

Hello!!

I have an application that consist of several windows forms. Lets call these
A,B and C for simplicity.
I have one main meny where the user can choose window form A or B or C.

When a user bring up a window for the first time I create an instance
otherwise I just set visible = true.

When a user brings up a window form for example B and the user click on the
little cross
on the system bar I don't want to close the window form but insted hide the
window form
by setting visible = false.
When the user click on the little cross this event handler A_Closing below
is called.
So hide and show for a window form works good and cause no problem.

private void A_Closing(object sender, System.ComponentModel.CancelEventArgs
e)
{
meltPracCommonControl1.CheckChanged();
FormsManager.Instance.getElementYieldForm().Visible = false;
e.Cancel = true;
}


Now to my question: Assume you use this visible=true and visible=false and
you have a field on the form which
says firstPosNumber and you write -1 in this field and then you click on the
little cross to hide and then
bring up the same form again you will see -1 in the field firstPosNumber.

What I want to do is when the user bring up the window form for the second
time
I want to use a method that initialize the window form with (correct data
which is read from the db) data. Note I don't want to instance the
window form from the beginning using the c-tor. So for the example with
this -1 when the form was chosen for the second time
the database was read and return 1 in this field firstPosNumber.

So is it possible to have a call to a method that initialize a form before
the form is shown(visible=true).


//Tony
 
Hi,

tony said:
Hello!!

I have an application that consist of several windows forms. Lets call
these
A,B and C for simplicity.
I have one main meny where the user can choose window form A or B or C.

When a user bring up a window for the first time I create an instance
otherwise I just set visible = true.


Unless the forms have a heavy overload being created I STRONGLY advise you
not to do that. You may get into nasty errors of ownership, parenting, etc.


If for some reason you have to do it, consider using a Singleton pattern for
the form.

Even in this case try to not use ShowDialog but Show when you make a form
visible.


Again, try to avoid this situation
 
Back
Top