How to Disable The Cross X Button in Winform

I had this requirement to to not allow user to close a windows form by clicking the top-right cross button.  This can be done by checking the FormClosing Event.

 

private void DataCheckInspection_FormClosing(object sender, FormClosingEventArgs e)
{
    if (e.CloseReason == CloseReason.UserClosing)
    {
        e.Cancel = true;
    }
}

Advertisements