The original post - c-sharpcorner.com/forums/how-do-i-override-the-corner-quotxquot-so-the-dialog-box-does-not-close.
Commonly clicking the "X" in the corner of a dialog box closes the dialog box. How do I override the corner "X" so the dialog box does not close? See snipboard.io/kJZbzs.jpg.
public partial class dlgNumbers : Window
{
//------------------------------
public dlgNumbers()
{
InitializeComponent();
}
//------------------------------
To clarify further, I have a button that closes the dialog box, but the "X" in the corner should not close the dialog box.
Another option is to hide the "X" in the corner.
What do I mdify in the responses to the original post?
Mithilesh TataPosted Mar 8, 2024, 12:42 PM
To prevent the dialog box from closing when clicking the "X" button in the corner, you can handle the
Closingevent of the Window and set theCancelproperty of theCancelEventArgsparameter totrue. Here's how you can do it in yourdlgNumbersclass:With this code, clicking the "X" button will no longer close the dialog box. You can still provide a button to close the dialog box programmatically if needed.
Alternatively, if you want to hide the "X" button altogether, you can set the
WindowStyleproperty of the window toNone, which removes the standard window border including the close button. However, you'll need to provide a custom way for users to close the dialog box, such as adding a button within the dialog box interface.Choose the approach that best fits your application's requirements.
Tuhin PaulPosted Mar 9, 2024, 7:49 PM
To prevent the dialog box from closing when clicking the "X" button, you have two main approaches:
With this approach, clicking the "X" button will no longer close the dialog box. You can still provide a button to close the dialog box programmatically if needed.
By setting the WindowStyle property to None, you remove the standard window border, including the close button. However, you'll need to provide a custom way for users to close the dialog box, such as adding a button within the dialog box interface.