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

推荐订阅源

N
News and Events Feed by Topic
WordPress大学
WordPress大学
Vercel News
Vercel News
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
小众软件
小众软件
L
LangChain Blog
雷峰网
雷峰网
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
NISL@THU
NISL@THU
Scott Helme
Scott Helme
量子位
S
Security Affairs
T
Threat Research - Cisco Blogs
博客园_首页
云风的 BLOG
云风的 BLOG
D
Docker
AWS News Blog
AWS News Blog
腾讯CDC
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
U
Unit 42
Recent Announcements
Recent Announcements
Apple Machine Learning Research
Apple Machine Learning Research
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Last Watchdog
The Last Watchdog
C
Cybersecurity and Infrastructure Security Agency CISA
IT之家
IT之家
W
WeLiveSecurity
P
Privacy & Cybersecurity Law Blog
F
Full Disclosure
L
Lohrmann on Cybersecurity
The Hacker News
The Hacker News
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Y
Y Combinator Blog
S
Security @ Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
C
Check Point Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
PCI Perspectives
PCI Perspectives
I
InfoQ

博客园 - aroundall

挪窝了 Upgrade Zoomr to Pro 最近越来越喜欢玩游戏了 正在看《经济学原理》和《代码大全》 老了 哎,人都怎么了 还有一个月就要回去了 下午就要走了,出差,发一首齐豫的《菊叹》 纽曼的东西和服务都太次了,可以说是垃圾! Ms-Dos7.10安装盘 星期四就要走了 [转]IT开发工程师的悲哀 学点什么好呢? 移动硬盘坏了 今天去办护照了 我很无奈 要学习COBOL了 Where are we go? What is RAM Disk?
关于Form KeyDown事件的处理代码执行两次的问题
aroundall · 2006-01-12 · via 博客园 - aroundall

一、背景
        同事叫帮忙看看程序,程序是vb.net程序,描述:一个Form(有KeyDown事件处理代码Form1_KeyDown())上面有一些按钮,这些按钮都注册了KeyDown事件。按理说程序启动起来,界面出来后,即一特定的键只有按钮的KeyDown事件发生。不幸的是,击键一次会执行两次事件处理代码。主要代码如下:

 1
 2Public Class Form1
 3    Inherits System.Windows.Forms.Form
 4
 5    
 6
 7    Public Sub RegistEvent(ByVal ctrTarget As Control)
 8        AddHandler ctrTarget.KeyDown, AddressOf Me.Form1_KeyDown
 9
10        Me.RegistEvent(ctrTarget.Controls)
11
12    End Sub

13
14    Public Sub UnRegistEvent(ByVal ctrTargets As Control.ControlCollection)
15        Dim ctrTarget As Control
16
17        If (ctrTargets Is NothingThen
18            Return
19        End If
20
21        For Each ctrTarget In ctrTargets
22            Me.UnRegistEvent(ctrTarget)
23        Next
24    End Sub

25
26    Private Sub Form1_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles MyBase.Load
27
28        
29
30        If (Me._autoRegistEvent) Then
31            Me.RegistEvent(Me.Controls)
32        End If
33
34        
35
36    End Sub

37
38    Private Sub Form1_KeyDown(ByVal sender As ObjectByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
39
40        
41
42    End Sub

43
44    
45
46End Class

47


二、徒劳的探索
        由于是初接触.NET我也不知道该怎么办,只好step-by-step呗。昨天一个下午都没有跟踪出来,发现一切好像都很合适。这中间还搞了一个闹剧,说是把“Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown”中的“Handles MyBase.KeyDown”给去掉,呵呵。但是从这里我已经看出来了:该子程序仍然在处理Form1的KeyDown事件,这是关键中的关键,结果还是没有找出来为什么。
三、夜间的思考
        思考了好久,仍然想不出来新的见解……
四、问题的解决
        今天上班以来就把问题锁定在Form1上,不知道哪里出错了,估计是属性设置上有点问题。突然间发现
       
        将该项设为false时,发现一切都好了……哭笑不得
注:Form.KeyPreview 属性——获取或设置一个值,该值指示在将键事件传递到具有焦点的控件前,窗体是否将接收此键事件。