让文本框保持光标不离开

作者在 2015-11-30 09:46:37 发布以下内容
PUBLIC oform1

oform1=NEWOBJECT("form1")
oform1.Show
RETURN
DEFINE CLASS form1 AS form


    DoCreate = .T.
    Caption = "Form1"
    Name = "Form1"


    ADD OBJECT text1 AS textbox WITH ;
        Height = 20, ;
        Left = 72, ;
        Top = 36, ;
        Width = 100, ;
        Name = "Text1"


    ADD OBJECT list1 AS listbox WITH ;
        Height = 170, ;
        Left = 72, ;
        Top = 60, ;
        Width = 100, ;
        Name = "List1"


    PROCEDURE Init
        This.KeyPreview=.T.
        This.List1.Visible=.F.
        CREATE CURSOR tt (a1 c(10))
        INSERT INTO tt VALUES ("abcde")
        INSERT INTO tt VALUES ("xycde")
        INSERT INTO tt VALUES ("abcxy")
        INSERT INTO tt VALUES ("cdeab")
    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 This.Text1.Tag='1'
            If nKeyCode=13
                This.Text1.Value=This.List1.Value
                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
                Nodefault
            Endif
        Endif
    ENDPROC


    PROCEDURE text1.GotFocus
        This.Tag='1'
    ENDPROC


    PROCEDURE text1.LostFocus
        Thisform.List1.Visible=.F.
        This.Tag=''
    ENDPROC


    PROCEDURE text1.InteractiveChange
        If !Empty(This.Value)
            Thisform.list1.RowSource=Null
            Select a1 From tt Where Alltrim(This.Value)$a1 Into Cursor t1 Order By a1
            Thisform.list1.RowSourceType=6
            Thisform.list1.RowSource="t1.a1"
            If Reccount('t1')>0
                Thisform.List1.ListItemId=1
                Thisform.List1.Visible=.T.
            Else
                Thisform.List1.Visible=.F.
            Endif
        Else
            Thisform.List1.Visible=.F.
        Endif
    ENDPROC


ENDDEFINE
*
文本框(TextBox) | 阅读 2347 次
文章评论,共0条
游客请输入验证码
浏览402056次