"return no-apply" in GUI for .NET?

Posted by GSchug on 25-Jun-2009 01:27

Example:

Dialog box should not be closed as long as user has not entered valid data. In the old (sorry: "classic") UI, I would do that with a "return no-apply" in the Choose Trigger of the OK Button

But there are other thinkable examples for "return no-apply".

So how to prevent the default behavior to be executed in an event handler method in GUI for .NET?

Thanks for your help!

Best regards

Gunnar

All Replies

Posted by Admin on 25-Jun-2009 01:45

Hallo Herr Schug,

the FormClosing event is (and a Dialog Box is a System.Windows.Forms.Form) cancellable.

So in the Event Handler, you may use

ASSIGN e:Cancel = TRUE .   /* or what ever name you have chosen for the event arguments */

and the Form will not be closed.

e:CloseReason 

also tells you why the Form is being closed (during the event handler).

Don't set e:Cancel to FALSE, if the current event handler thinks (?), that the Form is OK to be closed. .NET Objects may have more than one event handler for the same event (not like Progress widgets) - and that might override a signal already set by a previously executed event handler.

Regarding the OK Button. In this case, I'd probably not use the DialogResult property of the OK button set to System.Windows.Forms.DialogResult:Ok. Then you may manually "close" the Form (and inform the caller about OK) when all data is correct, like this.

THIS-OBJECT:DialogResult = System.Windows.Forms.DialogReasult:OK .

THIS-OBJECT:Close ().

Posted by GSchug on 25-Jun-2009 02:19

Hallo Herr Fechner,

thank you for the fast response.

This solved my problem. My mistake was to try to cancel closing in the "ok-Button-Click"-Method. But this method comes with an "System.EventArgs" argument which does not support the "cancel" attribute.

I've added an event handler now for the "FormClosing" event. This handler comes with an "System.Windows.Forms.FormClosingEventArgs" argument which supports the "cancel" attribute.

Thank you very much!

Best regards

Gunnar

This thread is closed