Event.add<'T,'Del> Function (F#)

Runs the given function each time the given event is triggered.

Namespace/Module Path: Microsoft.FSharp.Control.Event

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Event.add : ('T -> unit) -> IEvent<'Del,'T> -> unit (requires delegate)

// Usage:
Event.add callback sourceEvent

Parameters

  • callback
    Type: 'T -> unit

    The function to call when the event is triggered.

  • sourceEvent
    Type: IEvent<'Del,'T>

    The input event.

Remarks

This function is named Add in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example

The following code example shows how to use the Event.add function.

let form = new Form(Text = "F# Windows Form",
                    Visible = true,
                    TopMost = true)
form.MouseMove
    |> Event.filter ( fun evArgs -> evArgs.X > 100 && evArgs.Y > 100)
    |> Event.add ( fun evArgs ->
        form.BackColor <- System.Drawing.Color.FromArgb(
            evArgs.X, evArgs.Y, evArgs.X ^^^ evArgs.Y) )

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Control.Event Module (F#)

Microsoft.FSharp.Control Namespace (F#)