AcceptButton closes Form on Failure

  • Thread starter Christian Wilhelm
  • 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
 
C

Christian Wilhelm

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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
 
C

Christian Wilhelm

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
 
S

Stoitcho Goutsev \(100\) [C# MVP]

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
 
C

Christian Wilhelm

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
 

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