帮你顶一下,顺便贴一下代码,希望高手帮忙Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Const CB_SHOWDROPDOWN = &H14F Dim bDrop As BooleanPrivate Sub Combo1_Click() MsgBox "look at this stupid idiot!!!" End SubPrivate Sub Combo1_DropDown() bDrop = True End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 40 Then SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0 ElseIf KeyCode = 38 Then If Combo1.ListIndex = 0 Then If bDrop Then bDrop = False SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 0, 0 End If End If End If End SubPrivate Sub Form_Load() Combo1.AddItem "abcd" Combo1.AddItem "abcd1" Combo1.AddItem "abcd2" Combo1.AddItem "abcd3" End Sub
private isDo as boolean '表示是否执行Click事件Private Sub Combo1_Click() If Not isDo Then '如果是由箭头引发的就不执行后面代码。 Exit Sub End If End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 38 Or KeyCode = 40 Then '如果是上下箭头,则设置状态为假 isDo = False End If End Sub
Private isDo As Boolean Private Sub Combo1_Click() If Not isDo Then isDo = True '<----------回置状态 Exit Sub End If
Print Me.Combo1.Text
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 38 Or KeyCode = 40 Then '手工设置值 isDo = False End If End Sub
根据上面这位仁兄的意见,先改写如下,已基本解决该问题。Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Const CB_SHOWDROPDOWN = &H14F Dim bDrop As Boolean Private isDo As Boolean Private Sub Form_Load() isDo = True '设置为true时,当进入程序时直接用鼠标点击comob1,有效果,否则无效。 Combo1.AddItem "abcd" Combo1.AddItem "abcd1" Combo1.AddItem "abcd2" Combo1.AddItem "abcd3" End Sub Private Sub Combo1_Click() If Not isDo Then isDo = True '<----------回置状态 Exit Sub Else: MsgBox "safd" End If End SubPrivate Sub Combo1_DropDown() bDrop = True End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 40 Then isDo = False SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0 ElseIf KeyCode = 38 Then isDo = False If Combo1.ListIndex = 0 Then If bDrop Then bDrop = False SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 0, 0 End If End If End If
End SubPrivate Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) '如果没有这一句,则当用键盘操作后在一定情况下(不好描述,自己多试一试)会出现鼠标点击无响应的状态 If Combo1.Text = Combo1.List(0) Then isDo = True ’ End IfEnd Sub 请接续完善。
楼上兄弟; 下拉框的底色变化,而并不选取它, ========================== 可你用键入vbkeydown or vbkeyup 后,它还是选中了
所以我认为楼主的问题很容易解决,根本没必要那么复杂,直接取一个窗体级布尔量,在Combo1_KeyDown里面判断是vbkeyup 和vbkeydown,就改变该布尔量,在Combo1_Click里面加一判断就可以了,代码如下(在vb6.0+sp6+winXP通过): Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long Const CB_SHOWDROPDOWN = &H14FPrivate isDo As Boolean Private Sub Form_Load() isDo = True Combo1.AddItem "abcd" Combo1.AddItem "abcd1" Combo1.AddItem "abcd2" Combo1.AddItem "abcd3" End SubPrivate Sub Combo1_Click() If Not isDo Then isDo = True '<----------»ØÖÃ״̬ Exit Sub Else 'insert other code here End If End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 40 Then isDo = False ElseIf KeyCode = 38 Then isDo = False End If End Sub
我是用“鼠标” 点 出下拉框,然后用“键盘”上下键移动,找到想要的再选取,楼上各位好像是误解了我的意思 =================== 这样啊!那就在Combo1_KeyDown里面加一句就是: Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 40 Then isDo = False ElseIf KeyCode = 38 Then isDo = False ElseIf KeyCode = vbKeyReturn Then '将此时的Combo1.text传给你想要给予的那个东东 End If End Sub
private isDo as boolean '表示是否执行Click事件Private Sub Combo1_Click() If Not isDo Then '如果是由箭头引发的就不执行后面代码。 Exit Sub End If End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) If KeyCode = 38 Or KeyCode = 40 Then '如果是上下箭头,则设置状态为假 isDo = False End If End Sub
Option ExplicitDim IsKey As BooleanPrivate Sub Combo1_Click() If IsKey = False Then Debug.Print Now End If End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer) IsKey = True End SubPrivate Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer) IsKey = False End SubPrivate Sub Form_Load() Dim i As Long For i = 0 To 22 Combo1.AddItem Str(i) Next i End Sub
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const CB_SHOWDROPDOWN = &H14F
Dim bDrop As BooleanPrivate Sub Combo1_Click()
MsgBox "look at this stupid idiot!!!"
End SubPrivate Sub Combo1_DropDown()
bDrop = True
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0
ElseIf KeyCode = 38 Then
If Combo1.ListIndex = 0 Then
If bDrop Then
bDrop = False
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 0, 0
End If
End If
End If
End SubPrivate Sub Form_Load()
Combo1.AddItem "abcd"
Combo1.AddItem "abcd1"
Combo1.AddItem "abcd2"
Combo1.AddItem "abcd3"
End Sub
If Not isDo Then '如果是由箭头引发的就不执行后面代码。
Exit Sub
End If
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Or KeyCode = 40 Then
'如果是上下箭头,则设置状态为假
isDo = False
End If
End Sub
Private Sub Combo1_Click()
If Not isDo Then
isDo = True '<----------回置状态
Exit Sub
End If
Print Me.Combo1.Text
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Or KeyCode = 40 Then
'手工设置值
isDo = False
End If
End Sub
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const CB_SHOWDROPDOWN = &H14F
Dim bDrop As Boolean
Private isDo As Boolean
Private Sub Form_Load()
isDo = True '设置为true时,当进入程序时直接用鼠标点击comob1,有效果,否则无效。
Combo1.AddItem "abcd"
Combo1.AddItem "abcd1"
Combo1.AddItem "abcd2"
Combo1.AddItem "abcd3"
End Sub
Private Sub Combo1_Click()
If Not isDo Then
isDo = True '<----------回置状态
Exit Sub
Else: MsgBox "safd"
End If
End SubPrivate Sub Combo1_DropDown()
bDrop = True
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
isDo = False
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 1, 0 ElseIf KeyCode = 38 Then
isDo = False
If Combo1.ListIndex = 0 Then
If bDrop Then
bDrop = False
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, 0, 0
End If
End If
End If
End SubPrivate Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
'如果没有这一句,则当用键盘操作后在一定情况下(不好描述,自己多试一试)会出现鼠标点击无响应的状态
If Combo1.Text = Combo1.List(0) Then
isDo = True ’
End IfEnd Sub
请接续完善。
下拉框的底色变化,而并不选取它,
==========================
可你用键入vbkeydown or vbkeyup 后,它还是选中了
Option ExplicitPrivate Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const CB_SHOWDROPDOWN = &H14FPrivate isDo As Boolean
Private Sub Form_Load()
isDo = True
Combo1.AddItem "abcd"
Combo1.AddItem "abcd1"
Combo1.AddItem "abcd2"
Combo1.AddItem "abcd3"
End SubPrivate Sub Combo1_Click()
If Not isDo Then
isDo = True '<----------»ØÖÃ״̬
Exit Sub
Else
'insert other code here
End If
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
isDo = False
ElseIf KeyCode = 38 Then
isDo = False
End If
End Sub
===================
这样啊!那就在Combo1_KeyDown里面加一句就是:
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 Then
isDo = False
ElseIf KeyCode = 38 Then
isDo = False
ElseIf KeyCode = vbKeyReturn Then
'将此时的Combo1.text传给你想要给予的那个东东
End If
End Sub
If Not isDo Then '如果是由箭头引发的就不执行后面代码。
Exit Sub
End If
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 38 Or KeyCode = 40 Then
'如果是上下箭头,则设置状态为假
isDo = False
End If
End Sub
If IsKey = False Then
Debug.Print Now
End If
End SubPrivate Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
IsKey = True
End SubPrivate Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
IsKey = False
End SubPrivate Sub Form_Load()
Dim i As Long
For i = 0 To 22
Combo1.AddItem Str(i)
Next i
End Sub