Hello,
I can not get the second form to completly close.
On form 1, I perform
if (m_FrmIdentify == null){
nFrmIdentify = new frmIdentify();
}
if
(m_FrmIdentify.Visible == true){
FrmIdentify.Loadss();}
else{
mFrmIdentify.Show();
}
In form 2, on close
I tried callinig this.close() and this.hide(); Neiter of which make the call above mFrmIdentify == null
so that I can reopen the same form again.
THanks.
SamPosted Aug 14, 2007, 5:22 AM
Hi,
I think your problems is that by default when you close a form the form's Dispose() method is called. This causes an exception when methods of the form are called but doesn't make the varibale to the form == null.
A possible solution is to handle the 2nd form's FormClosing event like so:
private void Form2_FormClosing(object sender, FormClosingEventArgs e){
e.Cancel =
true; this.Hide();}
Hope this helps,
Sam
j_sen21Posted Aug 13, 2007, 10:53 PM
Sorry I reposted here, I just got sloppy. Its one form. Loadss is just a random function that it performs if the form has already been created and is visible.
//does this check because if its already created and open, then it wont create another form
I cant create a new form everytime, only when its not already created and open.
if (mFrmIdentify == null)
{
//creates a new form if one is not open.
}
else
{
//When a user interacts with the first form while form mFrmIdentify is already open it comes in here.
}
Thanks.
Jan MontanoPosted Aug 13, 2007, 9:57 PM
You have a frmIdentify Class but you also called FrmIdentify.Loadss() which I'm guessing FrmIdentify is another class?
What's the definition/name of your form1 & form2? I'm assuming form2 is m_FrmIdentify?.
You could try to just Hide m_FrmIdentify instead of closing it then check if it is visible or not. Here's my suggestion...
if (m_FrmIdentify == null)
{
}
else
{
}
j_sen21Posted Aug 13, 2007, 4:23 PM
No, it will only stay visible as long a user doesnt close it (mFrmIdentiy.close())
Because a user can still change things on form 1, mFrmIdentiy updates because it is still open (mFrmIdentify != null) and visible. Otherwise if mFrmIdentity is not open, it opens it.
Thanks.
I guess the only thing that does work is this line if (mFrmIdentify == null) in form 1, then do something.
It works the first time when mFrmIdentify form hasnt been opened yet. But then I close mFrmIdentify, and then try to reload the form again, it thinks that mFrmIdentify is not null anymore. I need to null mFrmIdentify from the closing event or other code that performs the same operation. I was thinking of writing a integer to a file to say the form is open or closed.
Richard BlythePosted Aug 13, 2007, 3:48 PM
I'm not sure what your trying to accomplish by all this. Are you trying to make a form that will always stay visible? If a better way would be to trap the form's "FormClosing" event and set the cancel property to true. e.Cancel = true;
If this hasn't answered your question, please write back.
Cheers!
Richard