How to tell why OnClosing was invoked

A

Andreas Selle

Hi,

right now I am facing the following Problem and cannot find a solution for
it:

In my Dialog (Form shown with ShowDialog) I have some field validation code
inside the overridden OnClosing method. Whenever the user tries to close the
Form (usually by tapping OK) with some invalid input I show a nice message
and prevent that the Form is closed. Works great.

There is one caveat however: Apart from tapping OK, the Form may also be
closed by terminating the application through a task manager that sends
WM_CLOSE to the actual Form Window. As expected, in this case OnClosing will
be called, too. However, in this case I would prefer to not validate the
input, but rather ignore any false inputs such that the application can be
shut down silently and gracefully. This raises the problem how to tell
whether the Form was closed by tapping OK or whether it was closed through
some other means.

My first idea was to check the DialogResult property, but this always
contains DialogResult.None when OnClosing is invoked.

Does anybody have an idea how to solve this problem?

Thanks

Andreas
 
N

Nick Randolph

Probably the easiest approach would be to move your validation out of the
onclosing event and either make it real time (ie some indicator on the form
to indicate if the information is valid) or place the validation inside the
event handler for a button. Although the Pocket PC guidelines promotes the
use of Ok, feedback from customers tends to indicate that this is confusing
as they are expecting that to be a close button.

Nick
 
A

Andreas Selle

Hi,

thanks for your response.

I also thought that it would be probably best to just have no OK system
control at the top at all, but rather provide "Done" and "Cancel"
softkeys/menu items just like on a Smartphone. This would enable me to make
a difference between tapping on "Done", "Cancel" and WM_CLOSE and act
accordingly.

Perhaps this violates some Pocket PC design guide or even prevents a
"Designed for Windows Mobile" certification.

How do others think of this design approach?

Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top