Remove the Close button and disable Alt+f4 to close

Source: Internet
Author: User

public int ctype = 0;

Private Const INT Gwl_style =-16;
Private Const int ws_sysmenu = 0x80000;
[System.Runtime.InteropServices.DllImport ("user32.dll", SetLastError = True)]
private static extern int GetWindowLong (IntPtr hWnd, int nIndex);
[System.Runtime.InteropServices.DllImport ("User32.dll")]
private static extern int SetWindowLong (IntPtr hWnd, int nIndex, int dwnewlong);
private void Window_Loaded (object sender, RoutedEventArgs e)
{
var hwnd = new System.Windows.Interop.WindowInteropHelper (this). Handle;
SetWindowLong (hwnd, Gwl_style, GetWindowLong (hwnd, Gwl_style) & ~ws_sysmenu);
}

private void Window_closing (object sender, System.ComponentModel.CancelEventArgs e)
{
if (CType < 1)
E.cancel = true;
}

private void Btnsave_mouseup (object sender, MouseButtonEventArgs e)
{
Try
{
CType = 1;

}
catch (Exception ex)
{
MessageBox.Show (ex. Message, "Hint", Messageboxbutton.ok, Messageboximage.error);
}
}
private void Btncancel_mouseup (object sender, MouseButtonEventArgs e)
{
Environment.exit (0);
}

Remove the Close button and disable Alt+f4 to close

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.