惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 最新话题
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
PCI Perspectives
PCI Perspectives
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
H
Heimdal Security Blog
S
Security @ Cisco Blogs
N
News | PayPal Newsroom
J
Java Code Geeks
罗磊的独立博客
Security Archives - TechRepublic
Security Archives - TechRepublic
N
News and Events Feed by Topic
V
V2EX
WordPress大学
WordPress大学
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
www.infosecurity-magazine.com
www.infosecurity-magazine.com
月光博客
月光博客
AI
AI
小众软件
小众软件
The GitHub Blog
The GitHub Blog
MongoDB | Blog
MongoDB | Blog
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
美团技术团队
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tailwind CSS Blog
S
Schneier on Security
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
B
Blog RSS Feed
Forbes - Security
Forbes - Security
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
人人都是产品经理
人人都是产品经理
云风的 BLOG
云风的 BLOG
Jina AI
Jina AI
Cisco Talos Blog
Cisco Talos Blog
U
Unit 42
Project Zero
Project Zero
H
Hacker News: Front Page
Y
Y Combinator Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
The Cloudflare Blog
大猫的无限游戏
大猫的无限游戏
S
Secure Thoughts
The Hacker News
The Hacker News
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - ColorSky

一定要找到你--IE隐藏文件 One sentence humor Self-service How do you add reference dll from GAC? 其实它不是我想象 关于目标 英语文化陷井 Everyday English - Glove Troubleshooting for Asp.net CS0016 error [ZZ]C#四种排序算法 唐僧的家书 minute_DesignPatternExplained(4) 管理的问题-聪明和笨的程序员 一个应用程序在某一时刻,到底是用了多少内存? 揭秘devenv 如何以两种启动模式启动 程序员,为你的程序而骄傲吧 算法的力量 minute_DesignPatternExplained(2) 转载同事写的:2006TechED感想
小议winForm的热键
ColorSky · 2008-08-07 · via 博客园 - ColorSky

转载请注明出处:彩色天空

winForm 应用开发,大都离不开winFrom + toolBar/Menu + some other Controls的模式。
其中快捷键的处理,我5年前就遇到了,现在发现还有人犯这个错误,觉得着实需要讲一下:
很多输入型控件都支持常用的Ctrl + C, Ctrl + V, Ctrl + X等热键,WinForm 在KeyPreview=true时也会捕捉这些快捷键被触发的Windows消息。

如果winFrom/ToolBar/Menu/Other Control这些控件,对快捷键都有处理,上级控件只要设置e.SuppressKeyPress属性值(Boolean 类型),就可以选择是否把key down消息传递给下级控件。这里的上下级是按控件的包含关系来说的。如winForm上有一个TextBox,winForm为上级控件,TextBox为下级控件。

唯一的例外是ToolBar/Menu控件,它最先截获消息,而且默认情况下,是它触发后,不再把消息往别的控件传送!

也就是说一旦快捷键设置在Menu上,除了相应的menuItem外,其他控件(包括winForm)将都收不到快捷键被触发的消息。这也是最容易导致bug的地方。为解决这个问题,我一般是在menuitem.click的处理事件中通过sendkeys.send()方法,把消息继续传递下去。

https://files.cnblogs.com/ColorSky/shortKey.zip

我做了一个事列程序,只在一个winForm上放了 menu 和 textbox控件,其中一个menuItem.shortkey属性设置为Ctrl + V。
在menuItem.click和winForm.Keydown事件中都加上Console.WriteLine()。

示例程序中很明显的说明了这个问题,outPut窗口的输出结果是:

Menu item click event is triggered!
Form Key Down event is triggered

!