Disabling the Close Button on a WinForms Form While Keeping Other Controls Active
I'm currently working on a WinForms application where I need to prevent the user from closing the main form until a specific operation is completed. However, I still want users to interact with other controls within the form while this operation is ongoing. I've tried overriding the `OnFormClosing` method to suppress the close event, but it seems to block all interactions on the form, which isnβt the desired behavior. Here's what I've implemented so far: ```csharp protected override void OnFormClosing(FormClosingEventArgs e) { if (operationInProgress) { e.Cancel = true; MessageBox.Show("Please wait until the operation is completed before closing the form."); } } ``` I set `operationInProgress` to `true` when the operation starts and back to `false` once it finishes. While this successfully prevents closing the form, any inputs on text boxes and buttons become unresponsive during the operation. I've also tried running the operation in a separate `Task` to keep the UI responsive, but the close event still doesn't allow the form to close. Is there a way to handle this such that the form remains interactive, yet the close button is disabled until the operation is fully completed? Iβm using .NET Framework 4.8 and Windows Forms for this application. Any suggestions on how to achieve this? Thanks!