Window close events in a winforms application

后端 未结 4 2121
生来不讨喜
生来不讨喜 2020-12-06 19:40

I am looking to prompt the user to save data when they close a form window in a winforms application. I can\'t figure out how to trigger the prompt to the user, should they

4条回答
  •  春和景丽
    2020-12-06 20:04

    If you override the form's OnFormClosing method, you have the chance to notify the user that changes have been made, and the opportunity to cancel closing the form.

    The event provides you with a FormClosingEventArgs instance which has a CloseReason property (which tells you why the form is closing) as well as a Cancel property, which you can set to True to stop the form from closing.

提交回复
热议问题