This project has moved. For the latest updates, please go here.
CLR Event Binding allows script to bind an .Net event using anonymous function.

Prerequisite

Since ReoScript need to access the .Net object before binding an event. The WorkMode to ScriptRunningMachine must be changed to enable AllowDirectAccess and AllowCLREventBind.
    ScriptRunningMachine srm = new ScriptRunningMachine();
    srm.WorkMode |= MachineWorkMode.EnableDirectAccess | MachineWorkMode.AllowCLREventBind;

See more about WorkMode.

Attach Event

To attach an event of an .Net object, the following syntax could be used:
    object.event = function;

For example: (does it look very JavaScript? :-))
    form.load = function() { alert('form loaded.'); };

Now the event 'load' of 'form' has been attached. Once the 'load' be fired in .Net program, the function in script will be called in script automatically.

Note: Only the public event declared in .Net could be bound in script.

Walkthrough

Create LinkLabel and put it on form in VisualStudio form editor:



Change it's name to 'link' and put it into script:
    srm.SetGlobalVariable("link", link);

Now bind 'click' event in script:
    link.click = function() {
        alert('Link Clicked!');
    };

Run this program, and click the LinkLabel, the event fired as shows:


Detach Event

To detach/remove an event binding, we should just set the property of event to null:
    object.event = null;

See Also

Last edited Jul 11, 2013 at 3:19 AM by unvell, version 3