Event.filter<'T,'Del> Function (F#)
Visual Studio 2012
Returns a new event that listens to the original event and triggers the resulting event only when the argument to the event passes the given function.
Namespace/Module Path: Microsoft.FSharp.Control.Event
Assembly: FSharp.Core (in FSharp.Core.dll)
// Signature:
Event.filter : ('T -> bool) -> IEvent<'Del,'T> -> IEvent<'T> (requires delegate)
// Usage:
Event.filter predicate sourceEvent
The following code example shows how to use the Event.filter function. In this example, mouse events are passed on only when the mouse pointer is in a certain region.
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) )