Tuesday, April 5, 2011

OnClosing event is not being called when Close, X, button is pressed. Windows Mobile.

I am new to Windows Mobile and created an app that needs to do some clean up when a Form is closed. When I click on the Close in the ControlBox it does not call the OnClosing event. This works fine in regular windows but is not working with my Windows Mobile device.

Here is my code:

protected override void OnClosing(System.ComponentModel.CancelEventArgs e) { ... }

I have also tried this with no luck:

Form.Closing += new System.ComponentModel.CancelEventHandler(WindBaseForm_Closing);

I would appreciate any help you can give.

From stackoverflow
  • Correct. The (X) button in Windows Mobile is called the "Smart Minimize" button and only minimizes the Form. Set the Form's MinimizeBox property to false and it will change to (OK) which will close the Form (and raise the event).

    For the gory details as to why this happens, read this.

    Lasse V. Karlsen : This article, which I've read before, only shows that MS didn't really know how the other devices worked. Palm did in fact close every program when you switched, it just had a nice policy that said that every app should strive to save and restore the exact state upon relaunch.
    ctacke : Palm never really "closed" apps because they never actually "loaded" in the same way that CE apps load. Palm ran the PDBs in place, jumping from the OS to the app code directly. It was not a multitasking OS, so it's really hard to draw a parallel that a Windows-only dev would understand.
  • wow I had the exact same problem, thanks a lot for the explanation.

    D

0 comments:

Post a Comment