文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>WinForm和WPF 屏蔽Alt+F4键

WinForm和WPF 屏蔽Alt+F4键

时间:2011-01-30  来源:面壁居士

WinForm:比WPF稍简单些

 

1         private void MyForm_KeyDown(object sender, KeyEventArgs e)
2         {
3             if (e.KeyCode == Keys.F4 && e.Modifiers == Keys.Alt)
4             {
5                 e.Handled = true;
6             }
7         }

 

 

 

WPF: 只要在PreviewKeyDown和PreviesKeyUp中做处理即可,代码如下:

  

 1         private bool AltDown = false;
 2         private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
 3         {
 4 
 5             if (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt)
 6             {
 7                 AltDown = true;
 8             }
 9             else if (e.SystemKey == Key.F4 && AltDown)
10             {
11                 e.Handled = true;
12             }
13             //else if (e.SystemKey == …… && AltDown) // 可以在此处添加 自己需要的快捷键。
14             //{
15             //    this.Close();
16             //}
17         }
18 
19         private void Window_PreviewKeyUp(object sender, KeyEventArgs e)
20         {
21             if (e.SystemKey == Key.LeftAlt || e.SystemKey == Key.RightAlt)
22             {
23                 AltDown = false;
24             }
25         }

 

 

相关阅读 更多 +
排行榜 更多 +
方块枪战战场安卓版

方块枪战战场安卓版

飞行射击 下载
战斗火力射击安卓版

战斗火力射击安卓版

飞行射击 下载
空中防御战安卓版

空中防御战安卓版

飞行射击 下载