TextBox+ListBox组成的MyComboBox控件
程序代码:
CLEAR ALL SET PATH TO "MyTools" SET PROCEDURE TO "MyForm" ADDITIVE SET PROCEDURE TO "MyComboBox" ADDITIVE Main() CLOSE PROCEDURES CLEAR ALL RETURN PROCEDURE Main() LOCAL loForm loForm = CREATEOBJECT("_Form") WITH loForm .Caption = "test MyComboBox" .ShowTips = .T. .Show ENDWITH READ EVENTS ENDPROC DEFINE CLASS _Form AS MyForm ADD OBJECT Combo1 AS MyComboBox WITH Top = 5, Left = 5, Height = 100, Width = 120 PROCEDURE Combo1.Init WITH This.lstList .Clear .AddItem("One") .AddItem("Two") .AddItem("Three") .AddItem("Fourth") .AddItem("Five") .AddItem("Six") .ListIndex = 1 ENDWITH ENDPROC ENDDEFINE
MyForm.PRG
程序代码:
DEFINE CLASS MyForm AS Form PROCEDURE Arrange FOR EACH obj IN This.Controls FOXOBJECT IF (VARTYPE(obj.CanArrange) == "L") .AND. obj.CanArrange obj.Arrange ENDIF NEXT ENDPROC PROCEDURE Activate This.Arrange ENDPROC PROCEDURE Resize This.Arrange ENDPROC PROCEDURE Destroy CLEAR EVENTS ENDPROC ENDDEFINE
MyComboBox.PRG
程序代码:
DEFINE CLASS MyComboBox AS Container BorderWidth = 0 CanArrange = .T. ADD OBJECT txtInput AS TextBox WITH Height = 25, ToolTipText = "按TAB选定当前列表项" ADD OBJECT lstList AS ListBox WITH ToolTipText = "鼠标滚动选项" PROCEDURE Arrange WITH This.txtInput .Top = 0 .Left = 0 .Width = This.Width ENDWITH WITH This.lstList .Top = This.txtInput.Top + This.txtInput.Height + 2 .Left = 0 .Height = This.Height - .Top .Width = This.Width ENDWITH ENDPROC PROCEDURE txtInput.InteractiveChange LOCAL lnIndex WITH This.Parent FOR lnIndex = 1 TO .lstList.ListCount IF ALLTRIM(This.Value) $ .lstList.ListItem(lnIndex) .lstList.ListIndex = lnIndex EXIT ENDIF NEXT IF lnIndex > .lstList.ListCount .lstList.ListIndex = 1 ENDIF ENDWITH ENDPROC #define K_TAB 9 PROCEDURE txtInput.KeyPress(tnKeyCode, tnShiftAltCtrl) IF tnKeyCode == K_TAB This.Value = This.Parent.lstList.Value ENDIF ENDPROC PROCEDURE lstList.MouseWheel(tnDirection, tnShift, tnXCoord, tnYCoord) WITH This IF tnDirection < 0 IF .ListIndex < .ListCount .ListIndex = .ListIndex + 1 ENDIF ELSE IF .ListIndex > 1 .ListIndex = .ListIndex - 1 ENDIF ENDIF ENDWITH ENDPROC PROCEDURE lstList.Click This.Parent.txtInput.Value = This.Value ENDPROC ENDDEFINE
运行画面
[此贴子已经被作者于2015-11-30 01:52编辑过]