AcceptButton closes Form on Failure

  • Thread starter Thread starter Christian Wilhelm
  • Start date Start date
C

Christian Wilhelm

Hi!

I have an AcceptButton on my Form. With pressing this Button some checks are
performed and only when they are all okay, then the Form should close.

Can I set this up in some way?
E.g. abort the Closing-Process of the Form...

Thank U very much,
Christian
 
Sorry,

I have found my Failure.
The Button's DialogResult-Attribute was setted to "OK" by the Designer.
I have changed this to None and now it works.

Thank U,
Christian
 
Christian,
The other possibilities would be to leave it DialogResult.OK and handle
form's Closing event. Here you can cancel closing if something's wrong
 
Hi Stoitcho,

thank you for your answer.
Only of reasons of curiousity: how can I do this, can you give me a keyword?

Thank you very much,
Christian

Stoitcho Goutsev (100) said:
Christian,
The other possibilities would be to leave it DialogResult.OK and handle
form's Closing event. Here you can cancel closing if something's wrong

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Christian Wilhelm said:
Hi!

I have an AcceptButton on my Form. With pressing this Button some checks
are
performed and only when they are all okay, then the Form should close.

Can I set this up in some way?
E.g. abort the Closing-Process of the Form...

Thank U very much,
Christian
 
Forms have Closing event you can ether hook on it or override OnClosing
virtual method. The event args object of this event has porperty Cancel. If
you set this property to true the form won't close.

Closing event is fired whenever the form closes.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Christian Wilhelm said:
Hi Stoitcho,

thank you for your answer.
Only of reasons of curiousity: how can I do this, can you give me a
keyword?

Thank you very much,
Christian

Stoitcho Goutsev (100) said:
Christian,
The other possibilities would be to leave it DialogResult.OK and handle
form's Closing event. Here you can cancel closing if something's wrong

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Christian Wilhelm said:
Hi!

I have an AcceptButton on my Form. With pressing this Button some
checks
are
performed and only when they are all okay, then the Form should close.

Can I set this up in some way?
E.g. abort the Closing-Process of the Form...

Thank U very much,
Christian
 
Hi Stoitcho!

Thank you very much for your explanation, I've got it.

Regards,
Christian

Stoitcho Goutsev (100) said:
Forms have Closing event you can ether hook on it or override OnClosing
virtual method. The event args object of this event has porperty Cancel. If
you set this property to true the form won't close.

Closing event is fired whenever the form closes.

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Christian Wilhelm said:
Hi Stoitcho,

thank you for your answer.
Only of reasons of curiousity: how can I do this, can you give me a
keyword?

Thank you very much,
Christian

Stoitcho Goutsev (100) said:
Christian,
The other possibilities would be to leave it DialogResult.OK and handle
form's Closing event. Here you can cancel closing if something's wrong

--
HTH
Stoitcho Goutsev (100) [C# MVP]


Hi!

I have an AcceptButton on my Form. With pressing this Button some
checks
are
performed and only when they are all okay, then the Form should close.

Can I set this up in some way?
E.g. abort the Closing-Process of the Form...

Thank U very much,
Christian
 
Back
Top