我写个程序,实现在按钮上可以用键盘操作,但是却不知道为什么执行不了:
private sub form_load()
command1(0).setfocus
end sub
private sub command1(0)_keypress(....)
if key = vbKeyW then
command1(0).caption = "asdf"
end if
end sub
请问大家怎么回事啊?执行的时候按下W键为什么没用啊?~~
private sub form_load()
command1(0).setfocus
end sub
private sub command1(0)_keypress(....)
if key = vbKeyW then
command1(0).caption = "asdf"
end if
end sub
请问大家怎么回事啊?执行的时候按下W键为什么没用啊?~~
If keyCode = VBKeyW Then
Me.ActiveControl.Caption = "asdf"
End If
设置窗口的KeyPreview为True
引用 1 楼 caozhy 的回复:写在Form_KeyPress里面:
If keyCode = VBKeyW Then
Me.ActiveControl.Caption = "asdf"
End If
设置窗口的KeyPreview为True试过,没用~~重试。
[/Quo好吧
e.ActiveControl.Caption = "asdf"没法确定是command数组中的哪一个啊??
省略的括号里面的东西很重要,是传递的参数,如index、keycode等
keyascii,显然的啦
但是还是不行~~搞不懂啊?
怎么是Command(0)_KeyPress() 呢?
If KeyAscii = vbKeyW Or KeyAscii = 119 Then
Command1(0).Caption = "asdf"
End If
End Sub大小写的问题,大写的时候才是 vbKeyW
Private Sub Command1_KeyDown(Index As Integer, KeyCode As Integer, Shift As Integer)
If KeyCode = vbKeyW Then
Command1(0).Caption = "asdf"
End If
End Sub这样也行
Private Sub Command1_KeyPress(Index As Integer, KeyAscii As Integer)
If UCase(Chr(KeyAscii)) = "W" Then
Command1(0).Caption = "asdf"
End If
End Sub
msgbox KeyAscii
End Sub
你看看是什么?
我10楼的代码有什么问题?