vb 用按键(方向键)让COMBO1显示下拉框 求代码

2024-11-22 17:07:35
推荐回答(4个)
回答1:

一、枚举进程和其ID时:
Combo1.AddItem 进程名称
Combo1.ItemData(Combo1.NewIndex) = 进程ID
二、选择Combo1中的进程名称的时候,另外一个控件取得该进程所对应的PID:
Private Sub Combo1_Click()
Form2.label1.Caption = Combo1.ItemData(Combo1.ListIndex)
End Sub

回答2:

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
Private Const CB_SHOWDROPDOWN = &H14F
Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
If KeyCode = 40 And Shift = 0 Then
SendMessage Combo1.hwnd, CB_SHOWDROPDOWN, True, 0&
End If
End Sub

回答3:

Private Sub Combo1_GotFocus()
SendKeys "%{Down}"
End Sub

回答4:

zx001z回答的好啊,简单又实用。