How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
来源:互联网 发布:stm8 ubuntu 编辑:程序博客网 时间:2024/06/06 09:01
转自http://windowscoding.com/blogs/blake/archive/2009/05/19/how-to-register-a-keyboard-shortcut-hot-key-in-a-net-windows-forms-application.aspx
1. WPF solution
public WindowMain() { InitializeComponent(); this.InputBindings.Add(new InputBinding(MyAppCommands.SaveAll, new KeyGesture(Key.F2, ModifierKeys.Control));); CommandBinding cb = new CommandBinding(MyAppCommands.SaveAll); cb.Executed += SaveAllDocuments; this.CommandBindings.Add(cb ); } private void SaveAllDocuments(object obSender, ExecutedRoutedEventArgs e) { }
2. ProcessCmdKey
protected override bool ProcessCmdKey(ref Message message, Keys keys) { switch (keys) { case Keys.F2 | Keys.Control: //Process action here. return false; } }
3.IMessageFilter
public class MyMainForm : System.Windows.Forms.Form, IMessageFilter{ const int WM_KEYDOWN = 0x100; const int WM_KEYUP = 0x101; public bool PreFilterMessage(ref Message m) { Keys keyCode = (Keys)(int)m.WParam & Keys.KeyCode; if (m.Msg == WM_KEYDOWN && keyCode == Keys.Escape) { Console.WriteLine("Ignoring Escape..."); return true; } return false; } private void MyMainForm_Load(object sender, System.EventArgs e) { Application.AddMessageFilter(this); } }
- How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
- .Net Windows Forms: How to Create a Custom Print Dialog
- .Net Windows Forms: How to Create a Custom Print Dialog
- .Net Windows Forms: How to Create a Custom Print Dialog
- .NET Windows Forms in a Nutshell
- 非NSResponder类捕捉按键消息[How to capture ESC key in a Cocoa application]
- How to Register a Host Concurrent Program in Applications
- HOW TO: Set a Windows Hook in Visual C# .NET
- HOW TO: Set a Windows Hook in Visual C# .NET
- Creating a Windows Forms Application
- A guide to using Paneled Forms, Multi-Splash Screens, SQL Express, and many more in Windows Application Development
- how to register a cell for UITableViewCell
- How to launch Windows applications (Notepad) / Call Batch files from a C#/.NET console application.
- How to embed an icon in a Qt application
- (全英文)How to install and run a simple Asp.Net 5 Application in a Docker Container
- How to send a keybord shortcut to the Excel.
- Using IE within a Windows Forms application
- How to deploy a web application on Windows Azure
- 2012年对自己的要求和期望:日行一“善”
- Building Coder(Revit 二次开发) - 分解DWG文件
- 关于C# 读取 写入 删除 注册表简单例子
- 基于Lucene全文检索引擎的扩展
- POSIX 学习笔记---工作流
- How to register a keyboard shortcut (hot key) in a .NET Windows Forms Application
- zt:-职业生涯步步高:一位资深经理人的职业生涯感悟
- STL之Trim
- C99标准 数据类型以及后缀
- 电影 《狂暴飞车》
- poj 3308 Paratroopers 最小割—最大流
- 自定义输出宏替代NSLog
- SQLServer2005宝典学习笔记(数据操纵部分)
- Android牟利之道(一)--界面嵌入有米广告