ClosingEventArgs is a class in C# that represents the arguments of the event that occurs when a form or a window is about to close. It contains information about whether the operation should be cancelled or not, along with the reason for the close event.
Code Example 1:
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (MessageBox.Show("Are you sure you want to exit?", "Exit", MessageBoxButtons.YesNo) == DialogResult.No) { e.Cancel = true; } }
In this example, the FormClosing event is handled, and when the user tries to close the window, a message box is displayed asking for confirmation. If the user clicks the "No" button, the event is cancelled and the window remains open.
Code Example 2:
private void App_FormClosing(object sender, FormClosingEventArgs e) { if (e.CloseReason == CloseReason.WindowsShutDown) { // do something before application exits } }
This code example handles the FormClosing event and checks the CloseReason property of the ClosingEventArgs to determine if the application is shutting down because of a user logoff or a system shutdown. If the application is shutting down due to system shutdown, some functionality can be implemented before the application exits.
The ClosingEventArgs class is part of the System.Windows.Forms assembly in the .NET framework.
C# (CSharp) ClosingEventArgs - 45 examples found. These are the top rated real world C# (CSharp) examples of ClosingEventArgs extracted from open source projects. You can rate examples to help us improve the quality of examples.