Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Eventbinding to a property
Message
De
04/02/2016 16:16:00
 
 
À
04/02/2016 02:24:39
Lutz Scheffler
Lutz Scheffler Software Ingenieurbüro
Dresden, Allemagne
Information générale
Forum:
Visual FoxPro
Catégorie:
Programmation Orientée Object
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
SAMBA Server
Database:
Visual FoxPro
Application:
Desktop
Divers
Thread ID:
01630781
Message ID:
01630868
Vues:
55
Hi Lutz
this is a working example how bindevent() function (to vfp controls here) works.see the methods init ,my and my1
this code binds all form controls to mouseEnter & mouseLeave events to color backgrounds randomly.

see how intercept the event with
*--- aevent create an array aEvents
N=Aevents( myArray, 0) &&returns the number of rows in the specified array. Typically, the number represents the number of event bindings.
*--- reference the calling object
loObject = myArray[1]
see AEVENTS( ) Function in foxhelp (very usefull)
in normal way must a code in any control separatly.run this test code:
Publi oform
oform=Createobject("asup")
oform.Show
Read Events
Retu
*
Define Class asup As Form
    Height = 370
    Width = 759
    ShowWindow = 2
    AutoCenter = .T.
    Caption = "Bindevent-Aevents"
    MaxButton = .F.
    Name = "Form1"

    Add Object text1 As TextBox With ;
        Value = "This textbox is binded to its mouseEnter/mouseLeave events", ;
        Height = 37, ;
        Left = 24, ;
        Top = 5, ;
        Width = 301, ;
        Name = "Text1"

    Add Object edit1 As EditBox With ;
        Height = 133, ;
        Left = 24, ;
        Top = 60, ;
        Width = 301, ;
        Value = "This textbox is binded to its mouseEnter/mouseLeave events", ;
        Name = "Edit1"

    Add Object container1 As Container With ;
        Top = 12, ;
        Left = 372, ;
        Width = 348, ;
        Height = 73, ;
        specialEffect=2,;
        Name = "Container1"

    Add Object grid1 As Grid With ;
        Height = 181, ;
        Left = 348, ;
        Top = 108, ;
        Width = 337, ;
        Name = "Grid1"

    Add Object label1 As Label With ;
        Caption = "", ;
        Height = 37, ;
        Left = 24, ;
        Top = 324, ;
        Width = 613, ;
        Name = "Label1"

    Add Object label2 As Label With ;
        AutoSize = .T., ;
        FontSize = 14, ;
        WordWrap = .T., ;
        Caption = "MouseEnter mouseLeave on any control to see the bindevent effect (proc my & my1)", ;
        Height = 90, ;
        Left = 72, ;
        Top = 204, ;
        Width = 245, ;
        ForeColor = Rgb(255,0,0), ;
        BackColor = Rgb(255,255,128), ;
        Name = "Label2"

    Procedure my
        Lparameters nButton, nShift, nXCoord, nYCoord
        *--- aevent create an array aEvents
        N=Aevents( myArray, 0)
        *--- reference the calling object
        loObject = myArray[1]
        Try
            With loObject
                .BackColor=Rgb(255*Rand(),255*Rand(),255*Rand())
                .Parent.label1.Caption="Name="+loObject.Name+"   class="+loObject.Class+"  backcolor="+Trans(loObject.BackColor)+" --return="+Trans(N)
            Endwith
        Catch
        Endtry
    Endproc

    Procedure my1   &&mouseEnter on any control
        Lparameters nButton, nShift, nXCoord, nYCoord
        *--- aevent create an array aEvents
        N=Aevents( myArray, 0)
        *--- reference the calling object
        loObject = myArray[1]
        Do Case
            Case !Lower(loObject.Name)=="grid1"
                Try
                    loObject.BackColor=Rgb(255,255,255)
                Catch
                Endtry
                Thisform.label1.Caption=""

            Otherwise

                With loObject   &&grid1
                    Rand(-1)
                    .SetAll("DynamicBackColor" , "IIF(MOD(RECNO( ), 2)=0,RGB(255,255,255), RGB(255*rand(),255*rand(),255*rand()))", "Column")
                    .Refresh
                Endwith
                Thisform.label1.Caption="Name="+loObject.Name+"   class="+loObject.Class+" -- grid colors reformatted !"+"  --return="+Trans(N)
        Endcase
    Endproc

    Procedure Load
        Sele * From Home(1)+"samples\data\customer" Into Cursor ycurs Readwrite
        Sele ycurs
        Locate
    Endproc

    Procedure Init
        With This.grid1
            .RecordSource="ycurs"
            .RecordSourceType=1
            .DeleteMark=.F.
            .GridLines=0
            .MousePointer=15
            .SetAll("DynamicBackColor","IIF(MOD(RECNO( ), 2)=0, RGB(255,255,255), RGB(0,255,0))", "Column")
            .Refresh
        Endwith

        *binding controls
        For i=1 To This.ControlCount
            This.Controls(i).MousePointer=15
            If Inlist(Lower(This.Controls(i).Class),"textbox","editbox","container","label","grid")
                Bindevent(This.Controls(i),"mouseEnter",Thisform,"my")
                Bindevent(This.Controls(i),"MouseLeave",Thisform,"my1")
            Endi
        Endfor
    Endproc

    Procedure Destroy
        Clea Events
    Endproc

Enddefine
*
*-- EndDefine: asup
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform