码迷,mamicode.com
首页 > 其他好文 > 详细

去掉关闭按钮同时禁用alt+f4进行关闭

时间:2016-05-16 12:43:41      阅读:132      评论:0      收藏:0      [点我收藏+]

标签:

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, "提示", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void btnCancel_MouseUp(object sender, MouseButtonEventArgs e)
{
Environment.Exit(0);
}

去掉关闭按钮同时禁用alt+f4进行关闭

标签:

原文地址:http://www.cnblogs.com/chiyueqi/p/5497371.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!