转发:13豆的
Public oform1
oform1=Newobject("form1")
oform1.Show
Return
Define Class form1 As Form
DoCreate = .T.
Caption = "Form1"
KeyPreview = .T.
Name = "Form1"
Add Object combo1 As ComboBox With ;
Height = 24, ;
Left = 48, ;
Style = 0, ;
Top = 24, ;
Width = 144, ;
Name = "Combo1"
Add Object list1 As ListBox With ;
Height = 97, ;
Left = 192, ;
Top = 84, ;
Visible = .F., ;
Width = 108, ;
Name = "List1"
Procedure Init
Create Cursor t1 (fl1 C(20))
For lnI=0 To 23
Insert Into t1 Values (Chr(65+lnI)+Chr(97+lnI)+'-'+Chr(66+lnI)+Chr(98+lnI)+'-'+Chr(67+lnI)+Chr(99+lnI)+Transform(lnI))
Endfor
Locate
Scan
(fl1)
Endscan
Endproc
Procedure KeyPress
Lparameters nKeyCode, nShiftAltCtrl
If (nKeyCode=5 Or nKeyCode=24 Or nKeyCode=13) And This.List1.Visible And This.List1.ListItemId>0 And '1'
If nKeyCode=13
(Thisform.List1.ListItemId,1)
&& 此种方式不会触发Text1的InteractiveChange事件
This.List1.Visible=.F.
Else
lnListID=Iif(nKeyCode=5,Max(This.List1.ListItemId-1,1),Min(This.List1.ListItemId+1,This.List1.ListCount))
This.List1.ListItemId=lnListID
(Thisform.List1.ListItemId,1)
Nodefault
Endif
Endif
Endproc
Procedure combo1.LostFocus
This.Tag=''
Endproc
Procedure combo1.KeyPress
Lparameters nKeyCode, nShiftAltCtrl
If Between(nKeyCode,48,57) ;
&& 0-9
Or Between(nKeyCode,97,122) ;
&& a-z
Or Between(nKeyCode,65,90) ;
&& A-Z
Or nKeyCode=7 ;
&& DEL
Or nKeyCode=127 ;
&& BACKSPACE
Or (nKeyCode>127 And nKeyCode<>160) && 汉字
Thisform.List1.Tag='1'
&& 自动筛选
Else
Thisform.List1.Tag=''
&& 不筛选
Endif
Endproc
Procedure combo1.InteractiveChange
If Thisform.List1.Tag='1'
Thisform.List1.Tag=''
lcCombo1Val=Upper(Alltrim(This.DisplayValue))
If !Empty(lcCombo1Val)
Thisform.List1.RowSource=Null
Select fl1 Into Cursor ct2 From t1 Where (Upper(fl1) Like "%&lcCombo1Val.%")
Thisform.List1.RowSourceType=6
Thisform.List1.RowSource="ct2.fl1"
If Reccount('ct2')>0
Thisform.List1.ListItemId=1
Thisform.List1.Visible=.T.
Else
Thisform.List1.Visible=.F.
Endif
Else
Thisform.List1.Visible=.F.
Endif
Endif
Endproc
Procedure combo1.DropDown
Thisform.List1.Visible=.F.
Thisform.List1.Tag=''
Endproc
Procedure combo1.GotFocus
This.Tag='1'
Endproc
Procedure list1.MouseEnter
Lparameters nButton, nShift, nXCoord, nYCoord
This.Refresh
&& 解决鼠标移到其他控件(部分遮挡本控件)后,又移回本控件的显示问题
Endproc
Procedure list1.Init
This.Move(,,,100)
&& 目的是显示在 Combo1 的正下方,让人看起来像是 Combo1 的下拉框
Endproc
Procedure list1.Click
(Thisform.List1.ListItemId,1)
This.Visible=.F.
Endproc
Enddefine