当前位置:网站首页>Differences and connections of previewkeydown, Keydown, keypress and Keyup in C WinForm
Differences and connections of previewkeydown, Keydown, keypress and Keyup in C WinForm
2022-07-26 08:08:00 【51CTO】
1、 Key events occur in the following order :
PreviewKeyDown
KeyDown
KeyPress
KeyUp
2、KeyDown After triggering , Not necessarily triggered KeyUp, When KeyDown Press after , Drag the mouse , Then it won't trigger KeyUp event .
3、 Definition
PreviewKeyDown: With the focus on this control , Occurs when there is a key action ( stay KeyDown Before the event ).
Note :
Some keys , such as Tab、Return、Esc And arrow keys , It is usually ignored by some controls , Because they are not considered input keys . for example , By default ,Button Control ignores arrow keys . Usually pressing the arrow key will move the focus to the previous or next control . Arrow keys are considered navigation keys , Pressing these keys usually does not trigger Button Of KeyDown event . however , Press Button The arrow keys of will indeed trigger PreviewKeyDown event . By providing Button Handle PreviewKeyDown Event and handle IsInputKey Property is set to true, It can be raised when pressing the arrow key KeyDown event . however , If you handle the arrow keys , Then the focus will no longer move to the previous or next control .
KeyDown: Occurs when a key is pressed while the control has focus .
Note :
To process keyboard events only at the form level and not allow other controls to receive keyboard events , Please put the KeyPress In the event handling method KeyPressEventArgs.Handled Property is set to true. Some key , Such as Tab、Return、Esc And arrow keys , Automatically processed by the control . To make these keys trigger KeyDown event , Must be overridden in every control on the form IsInputKey Method . Used to rewrite IsInputKey The code of needs to determine whether a special key is pressed , And you need to return a true value . No need to rewrite IsInputKey Method , You can deal with PreviewKeyDown Incident and will IsInputKey Property is set to true. For code examples , Please see the PreviewKeyDown event .
KeyPress: Occurs when a key is pressed while the control has focus .( The following will say and KeyDown The difference between )
Note :
KeyPress Events cannot be raised by non character keys ; But non character keys can trigger KeyDown and KeyUp event .
Use KeyChar Attribute sampling run-time keystrokes , And use or modify a subset of commonly used keystrokes .
To process keyboard events only at the form level and not allow other controls to receive keyboard events , Please put the KeyPress In the event handling method KeyPressEventArgs.Handled Property is set to true.
KeyUp: Occurs when the key is released when the control has focus .
Note :
To process keyboard events only at the form level and not allow other controls to receive keyboard events , Please put the KeyPress In the event handling method KeyPressEventArgs.Handled Property is set to true. Some key , Such as Tab、Return、Esc And arrow keys , Automatically processed by the control . To make these keys trigger KeyUp event , Must be overridden in every control on the form IsInputKey Method . Used to rewrite IsInputKey The code of needs to determine whether a special key is pressed , And you need to return a true value .
4、KeyPress and KeyDown 、KeyPress The difference between
KeyPress It's mainly used to capture numbers ( Be careful : Include Shift+ Symbols of numbers )、 Letter ( Be careful : Include case )、 Keyboards, etc. in addition to F1-12、SHIFT、Alt、Ctrl、Insert、Home、PgUp、Delete、End、 PgDn、ScrollLock、Pause、NumLock、{ Menu key }、{ Start button } And outside the arrow keys ANSI character
KeyDown and KeyUp You can usually capture the keyboard except PrScrn All the buttons ( There are no special keys for special keyboards )
KeyPress Only a single character can be captured
KeyDown and KeyUp You can capture key combinations .
KeyPress You can capture the case of a single character
KeyDown and KeyUp For single character capture KeyValue It's all a value , That is, you can't judge the case of a single character .
KeyPress The keyboard doesn't distinguish between the main character and the keypad .
KeyDown and KeyUp Distinguish between numeric characters on the keypad and on the main keyboard .
among PrScrn Key KeyPress、KeyDown and KeyUp Can't capture .
Note :
KeyDown Keyboard input cannot be captured , Pay attention to the window keypreview Property is set to true
stay winform Capture the key events of control keys such as up, down, left and right keys in
边栏推荐
- ORACLE 官方文档
- Stm8 official library file download
- JSP built-in object (implicit object)
- table 固定特定行
- Logical volume management (LVM)
- Libevent custom event (asynchronous)
- 2022-07-09 group 5 Gu Xiangquan's learning notes day02
- Brief introduction to XML
- How to determine the authenticity of the website you visit -- certificate system
- Summary of traversal methods of list, set, map, queue, deque and stack
猜你喜欢

AQS implementation principle

JSP implicit object servlet object

Rack server expansion memory

Use js to count the number of occurrences of each string in the string array, and format it into an object array.

FTP service

JSP built-in object (implicit object)

【 fastjson1.2.24反序列化漏洞原理代码分析】
![[fastjson1.2.24 deserialization vulnerability principle code analysis]](/img/14/8f6a75fe5f06c19eeff9c7204979c3.png)
[fastjson1.2.24 deserialization vulnerability principle code analysis]

要不你给我说说什么是长轮询吧?

万字长文 | 深入理解 OpenFeign 的架构原理
随机推荐
Use of views
This is a picture
2022/7/12 exam summary
2022/7/17 exam summary
Web side 3D visualization engine hoops communicator reads 10g super large model test | digital twin Technology
Recurrence of strtus2 historical vulnerability
FTP service
Traversal mode of list, set, map, queue, deque, stack
2022/7/7 exam summary
JSP implicit object -- scope
Sort sort IP addresses
外卖小哥,才是这个社会最大的托底
JSP built-in object (implicit object) -- input / output object
The difference between LinkedList and ArrayList
Lambda and stream
Implementation class under map interface
General Dao interface design
Burp Suite-第二章 Burp Suite代理和浏览器设置
2022/7/9 exam summary
IDEA settings设置快捷键实现字符串中的英文字母转大小写