当Combox控件得到焦点后,按[向下键]自动弹出下拉菜单,并选中第一行,接着按向下向上键进行选择,再按回车选中一个选项,再按回车换到一
当Combox控件得到焦点后,按[向下键]自动弹出下拉菜单,并选中第一行,接着按向下向上键进行选择,再按回车选中一个选项,再按回车换到一个能得到焦点的控件。
问题点数:20、回复次数:6Top
1 楼TomJan(汤木鱼)回复于 2003-09-03 09:26:49 得分 5
你试试下面的代码,能否解决你的问题:
Private Sub Combo1_GotFocus()
SendKeys "{f4}"
End Sub
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
End Sub
Top
2 楼liul17(溜溜)回复于 2003-09-03 09:33:00 得分 5
以下状况假设我在 Form_Load 中自动下拉 Combo1.
'以下声明用于16位
Const WM_USER = &H400
Const CB_SHOWDROPDOWN = (WM_USER + 15)
Private Declare Function SendMessage Lib "User" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
'以下声明用于32位
Const CB_SHOWDROPDOWN = &H14F
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 Sub Form_Load()
Combo1.AddItem "11111"
Combo1.AddItem "22222"
Combo1.AddItem "33333"
Combo1.AddItem "44444"
Combo1.AddItem "55555"
Combo1.AddItem "66666"
'Form_Load 即自动下拉 Combo1
Dim nret As Long
nret = SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub
Top
3 楼liul17(溜溜)回复于 2003-09-03 09:35:30 得分 0
上面的好像有些问题
Option Explicit
'以下状况假设我在 Form_Load 中自动下拉 Combo1.
'以下声明用于16位
Const WM_USER = &H400
Const CB_SHOWDROPDOWN = (WM_USER + 15)
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
'以下声明用于32位
Const CB_SHOWDROPDOWN = &H14F
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 Sub Form_Load()
Combo1.AddItem "11111"
Combo1.AddItem "22222"
Combo1.AddItem "33333"
Combo1.AddItem "44444"
Combo1.AddItem "55555"
Combo1.AddItem "66666"
'Form_Load 即自动下拉 Combo1
Dim nret As Long
nret = SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, 1, ByVal 0&)
End Sub
Top
4 楼liul17(溜溜)回复于 2003-09-03 09:37:48 得分 0
上面代码能实现 你所说的 (当Combox控件得到焦点后,按[向下键]自动弹出下拉菜单,并选中第一行,接着按向下向上键进行选择,再按回车选中一个选项)
至于(再按回车换到一个能得到焦点的控件。)
可通过
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{TAB}"
End If
End Sub
Top
5 楼lzj34(缘来如此)回复于 2003-09-03 09:49:26 得分 0
楼上已经讲得够清楚了,我试过好像没报错Top
6 楼ch21st(www.blanksoft.com)回复于 2003-09-03 09:53:00 得分 10
这段代码可以满足你的要求
测试时,选中check1就是你要的效果
Private Declare Function SendMessageLong Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const CB_GETEXTENDEDUI = &H156
Private Const CB_SETEXTENDEDUI = &H155
Public Property Let ComboExtendedUI( _
ByRef cboThis As ComboBox, ByVal bState As Boolean _
)
' Set whether combo box drops down using the Down Arrow or not:
SendMessageLong cboThis.hwnd, CB_SETEXTENDEDUI, Abs(bState), 0
End Property
Public Property Get ComboExtendedUI( _
ByRef cboThis As ComboBox _
) As Boolean
' Get whether combo box drops down using the Down Arrow or not:
ComboExtendedUI = (SendMessageLong(cboThis.hwnd, CB_GETEXTENDEDUI, 0, 0) <> 0)
End Property
Private Sub Check1_Click()
' Toggle whether the Combo box will drop
' down when the down arrow is clicked or
' not:
ComboExtendedUI(Combo1) = (Check1.Value = Checked)
End Sub
Private Sub Form_Load()
Dim i As Long
' Add some test items:
For i = 1 To 20
Combo1.AddItem "Test Item " & i
Next i
End Sub
Top




