回 帖 发 新 帖 刷新版面

主题:求教关于空格键打开COMBOBOX下拉框看不到效果的问题

Private Sub Combo1_KeyPress(KeyAscii As Integer)

If KeyAscii = 32 Then
    SendKeys "%{DOWN}"
  End If
End Sub

这个代码表示发送alt+down 打开下拉框,(我的机器实验过,如果直接按键这两个可以打开)。但是通过SENDKEYS的方式不行。SENDKEYS发送其他的键都可以有效果的![em1][em1]

回复列表 (共3个回复)

沙发

Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then
        SendKeys "%{DOWN}"
    End If
End Sub

Private Sub Form_Load()
    Form1.KeyPreview = True
End Sub

板凳

先谢谢你!但是,我粘贴后没有效果的!!
Private Sub Form_KeyPress(KeyAscii As Integer)
    If KeyAscii = 32 Then
        SendKeys "%{DOWN}"
    End If
End Sub

Private Sub Form_Load()
    Combo1.AddItem "A"
    Combo1.AddItem "B"
    Form1.KeyPreview = True
End Sub
[em7]

3 楼

在我的机器上你的代码是有效的:

Private Sub Form_Load()
Combo1.AddItem "A"
Combo1.AddItem "B"
End Sub

Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 32 Then SendKeys "%{DOWN}"
End Sub

按一次空格,打开下拉框,再按一次就收起,如果你的不能,检查一下在Combo1的KeyUp、KeyDown、Click等事件中是否有相冲突的代码

我来回复

您尚未登录,请登录后再回复。点此登录或注册