Good day. Can you please tell me how to remap the button for closing the program (a cross in the corner)? I want to hang on her another action.

Thanks in advance!

  • one
    Intercept the event at the press of a button. - Alexander Semikashev

1 answer 1

https://msdn.microsoft.com/ru-ru/library/system.windows.forms.form.formclosing(v=vs.110).aspx

FormClosing The event occurs when the form is closed. If the form closes, it is deleted, freeing all the resources associated with the form. When you cancel this event, the form remains open. To cancel the closing of the form, set the Cancel Properties FormClosingEventArgs is passed to the event handler for true .

If the form is displayed as a modal dialog box, clicking the Close button (the button with an X sign in the upper right corner of the form) causes the form to be hidden and DialogResult Set the DialogResult.Cancel properties. You can override the value assigned to the DialogResult Properties when the user clicks the Close button, setting the DialogResult property in the event handler for the FormClosing form event.

  • Thank! FormClosing perfectly performs. Question on filling) And if it is necessary that the functions of ALT + F4 remain? - technor
  • one
    @technor, suppose that: declare the global variable qqw = true, catch the event pressing the key combination alt + f4, change qqw = false, call the Form.FormClosing event, in the handler of which we write: e.Cancel = qqw - qwabra
  • Thank you very much!! Works! - technor
  • one
    @technor, tick the answer with a green check mark - it will bring me a little closer to the ability to leave comments under other people's messages. ru.stackoverflow.com/help/someone-answers section "Mark the answer as a solution" - qwabra
  • one
    @technor, as an option - write the answer yourself with an example of working code and mark it as a solution. I think in this case it will be appropriate. You can also mention the outdated Form.Closing method - qwabra