By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,214 Members | 1,473 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,214 IT Pros & Developers. It's quick & easy.

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

P: n/a
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().Visibl e = 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
May 11 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

"tony" <jo*****************@telia.com> wrote in message
news:Oe****************@TK2MSFTNGP05.phx.gbl...
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

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 11 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.