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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
W
WeLiveSecurity
O
OpenAI News
N
News and Events Feed by Topic
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
云风的 BLOG
云风的 BLOG
N
News | PayPal Newsroom
H
Hacker News: Front Page
博客园_首页
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Schneier on Security
宝玉的分享
宝玉的分享
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Y
Y Combinator Blog
Cyberwarzone
Cyberwarzone
Microsoft Security Blog
Microsoft Security Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
GbyAI
GbyAI
Cloudbric
Cloudbric
TaoSecurity Blog
TaoSecurity Blog
人人都是产品经理
人人都是产品经理
P
Palo Alto Networks Blog
M
MIT News - Artificial intelligence
G
GRAHAM CLULEY
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
Last Week in AI
Last Week in AI
T
Troy Hunt's Blog
L
Lohrmann on Cybersecurity
www.infosecurity-magazine.com
www.infosecurity-magazine.com
P
Proofpoint News Feed
Blog — PlanetScale
Blog — PlanetScale
量子位
博客园 - 聂微东
S
Securelist
博客园 - 三生石上(FineUI控件)
F
Full Disclosure
G
Google Developers Blog
L
LINUX DO - 热门话题
P
Proofpoint News Feed
AI
AI
PCI Perspectives
PCI Perspectives

博客园 - lichdr

高德地图热力图的Flutter实现 App消息推送的简单实现 nginx访问日志过滤(多条件) CAS的service参数验证 自定义Token的CAS登录 单元格的计算 表格行列的删除 表格行列的移动 FastReport的一些另类用法 FastReport分组页码 RFID会议签到系统总结(二十二)――系统中的模式 RFID会议签到系统总结(二十一)――服务端的通讯 RFID会议签到系统总结(二十)――数据窗体状态控制 RFID会议签到系统总结(十九)――单数据窗体 RFID会议签到系统总结(十八)――菜单与工具栏的加载 RFID会议签到系统总结(十六)――菜单与工具栏按钮的改造(上) RFID会议签到系统总结(十五)――管控端的窗体组织 RFID会议签到系统总结(十四)――管控端业务模块的加载 RFID会议签到系统总结(十三)――模块概述(下)
RFID会议签到系统总结(十七)――菜单与工具栏的改造(下)
lichdr · 2007-07-23 · via 博客园 - lichdr

经过上一篇定义的两个接口,菜单与工具栏基本上符合了Command模式的样子,接下来应该可以在系统中加载了。但理论上照着模式是一回事,实实在在的写代码又是另一回事。

我们很遗憾地发现ToolBarButton这个类根本没有单击事件,甚至跟UI有关的事件都没有一个,因为它根本就不是从Control继承的,而是从Component继承的。工具栏按钮单击是从工具栏ToolBarButtonClick事件来的,就是说如果你要挂一段单击工具栏上单个按钮时发生动作的代码得挂在ToolBar的事件上,除些之外别无它法,很奇怪的设计。这种ToolBar只能用在静态的地方(其实即使是静态的地方,这个ButtonClick事件也是很糟糕的,以后会看到静态工具栏的这个变态事件),对于动态工具栏.Net Framework自带的这个ToolBar实在是无能为力。

没辙了,改吧。我们自己放个单击事件出来。下面是ToolBarButton的完整代码:

ToolBarButton

为了让ToolBar能认识这个Button,我们还得对ToolBar作点小小的改造,要让它可以触发ToolBarButton的单击事件。

       protected override void WndProc(ref Message m) {

           if (m.Msg == 0x2111){

              int index = ((int) m.WParam) & 0xffff;

              ToolBarButton button = this.Buttons[index];

              if (button != null) {

                  CommandToolBarButton commandBtn = button as CommandToolBarButton;

                  if (commandBtn != null){

                     commandBtn.DoOnClick();

                  }else{

                     ToolBarButtonClickEventArgs args1 = new ToolBarButtonClickEventArgs(button);

                     this.OnButtonClick(args1);

                  }

              }

           }else

              base.WndProc (ref m);

           base.ResetMouseEventArgs();

       }

上面代码里有个Magic Number,它在Win32 API里表示进入菜单循环消息(WM_ENTERMENULOOP,注意不是写在单击消息里的),因为项目里这种Message常量用得不多,就偷懒一下直接写了。