窗体运行时,Form的KeyPreview已经设置为true,如何捕获用户按Del键?
如下的过程,能捕获用户按esc键,但是不能捕获用户按del键。
Private Sub Form_KeyPress(KeyAscii As Integer)
If KeyAscii = 27 Then
Unload Me
ElseIf KeyAscii = 127 Then
' call a sub to del somthing
End If
End Sub
不知道代码该如何编写? 请高手帮忙。谢谢!
问题点数:20、回复次数:6Top
1 楼faysky2(出来混,迟早是要还嘀)回复于 2006-03-04 16:32:17 得分 10
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyDelete Then MsgBox "Del"
End SubTop
2 楼faysky2(出来混,迟早是要还嘀)回复于 2006-03-04 16:36:27 得分 2
或:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 46 Then MsgBox "Del"
End SubTop
3 楼rainstormmaster(暴风雨 v2.0)回复于 2006-03-04 16:37:13 得分 3
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyEscape Then
Unload Me
ElseIf KeyCode = vbKeyDelete Then
MsgBox "delete"
End If
End SubTop
4 楼woshihuzi(我是胡子)回复于 2006-03-04 17:25:56 得分 0
谢谢,楼上各位都是用的Keydown,那么,keypress和keydown有什么区别呢?Top
5 楼faysky2(出来混,迟早是要还嘀)回复于 2006-03-04 17:43:16 得分 5
应当使用 KeyDown 和 KeyUP 事件过程来处理任何不被 KeyPress 识别的击键,诸如:功能键、编辑键、定位键以及任何这些键和键盘换档键的组合等
功能键:标记为 F1 到 F12 之间的任意键
编辑键:是指 INSERT 键、DELETE 键或 BACKSPACE 键。
Top
6 楼woshihuzi(我是胡子)回复于 2006-03-05 16:33:34 得分 0
谢谢!揭帖。Top




