Hi

I have two forms, Form1 and FormInfo. In FormInfo I override Close(),
cancels and hides the form. However now Windows isn't able to close my app
automatically when the user tries to close Windows while my app also is
running. Can this be solved without abandoning overriding the form?

/Andreas Zita

Re: Override Close > Hide problem by Uchiha

Uchiha
Fri Sep 16 10:53:19 CDT 2005

Give FormInfo a ref to Form1.
Create a boolean value in Form1 called isClosing, create a public property
to acces this form FormInfo.
Hook up Form1.Closing event and set isClosing to true when this occurs and
call FormInfo.Close().

In the FormInfo.Close() override do an if on the Closing boolean.

if(parentForm.IsClosing)
{
this.Close();
}
else
{
this.Hide();
}

Is there a particular reason you have to override close?
It's just much tider to just intercept the closing event of FormInfo and
cancel it from Form1 rather than having to write unecessary overrides in
FormInfo.

HTH

Jax

"Andreas Zita" <andzi460@student.liu.se> wrote in message
news:e8gTZLtuFHA.992@TK2MSFTNGP12.phx.gbl...
> Hi
>
> I have two forms, Form1 and FormInfo. In FormInfo I override Close(),
> cancels and hides the form. However now Windows isn't able to close my app
> automatically when the user tries to close Windows while my app also is
> running. Can this be solved without abandoning overriding the form?
>
> /Andreas Zita
>
>



Re: Override Close > Hide problem by Andreas

Andreas
Fri Sep 16 11:17:05 CDT 2005

Thanks ... but it didn't work ...

I now intercept OnClosing of FormInfo from Form1 like this:

private void m_formInfo_Closing(object sender, CancelEventArgs e) {
if (!m_isClosing)
{
e.Cancel = true;
m_formInfo.Hide();
}
}

However I'm having trouble setting the m_isClosing variable. I don't know
where. I have tried this but it was still 'false' when entering
formInfo_Closing:

protected override void OnClosing(CancelEventArgs e) {
m_isClosing = true;
base.OnClosing(e);
}

I have also tried adding a method SuperClose() in FormInfo and running it
from Form1_Closing like this without success:

public void SuperClose() {
base.OnClosing(new CancelEventArgs(false));
}

Hmmmm I don't get this.
Thanks for any suggestions!

/Andreas Zita



Re: Override Close > Hide problem by Andreas

Andreas
Fri Sep 16 11:58:48 CDT 2005

Still no solution but this is what I think is happening:
When I close Form1 from the GUI, OnClosing in FormInfo is never run at all
(which is a bit odd?). So cancel is never set to true in this case.
Everything closes fine.
But when Windows tries to shut down and close my app it apparently begins
with closing FormInfo and _not_ Form1. Now OnClosing _is_ runned in FormInfo
and cancel _is_ set to true. This wouldn't be a problem if Windows would
continue and try to close Form1 but apparently this is'nt happening. When
Windows has tried to close FormInfo and finds it was cancelled it aborts the
shut down process completely!?

So, how do I know if when FormInfo is Closing, it was initiated by the user
or by the OS?

/Andreas Zita (frustrated)



Re: Override Close > Hide problem by Uchiha

Uchiha
Fri Sep 16 12:19:16 CDT 2005

Sorry I didn't understand the problem properly before. I've now replicated
it and it's a real interesting one.
However I did some hunting and found this:

http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=89686

That should do the trick and make up for my previous mis-information I hope.
:)

Jax

"Andreas Zita" <andzi460@student.liu.se> wrote in message
news:%23C7To$tuFHA.4020@TK2MSFTNGP12.phx.gbl...
> Still no solution but this is what I think is happening:
> When I close Form1 from the GUI, OnClosing in FormInfo is never run at all
> (which is a bit odd?). So cancel is never set to true in this case.
> Everything closes fine.
> But when Windows tries to shut down and close my app it apparently begins
> with closing FormInfo and _not_ Form1. Now OnClosing _is_ runned in
FormInfo
> and cancel _is_ set to true. This wouldn't be a problem if Windows would
> continue and try to close Form1 but apparently this is'nt happening. When
> Windows has tried to close FormInfo and finds it was cancelled it aborts
the
> shut down process completely!?
>
> So, how do I know if when FormInfo is Closing, it was initiated by the
user
> or by the OS?
>
> /Andreas Zita (frustrated)
>
>



Re: Override Close > Hide problem by Andreas

Andreas
Fri Sep 16 13:50:06 CDT 2005

Great!!! Thanks!
When doing my own research I found that CloseEventArgs in .net 2.0 had been
extended with a ClosingReason property to make it possible to know if close
was initiated by the user or by the system ... and I guess the solution you
found is somewhat the same but also for .net 1.x apps ....
Thanks a lot for your time Uchiha!

/Andreas Zita