Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Mastering F#

You're reading from   Mastering F# A comprehensive and in-depth guide to writing functional programs using F#

Arrow left icon
Product type Paperback
Published in Nov 2016
Publisher
ISBN-13 9781784393434
Length 264 pages
Edition 1st Edition
Languages
Arrow right icon
Authors (2):
Arrow left icon
Suhaib Fahad Suhaib Fahad
Author Profile Icon Suhaib Fahad
Suhaib Fahad
Alfonso García-Caro Núñez Alfonso García-Caro Núñez
Author Profile Icon Alfonso García-Caro Núñez
Alfonso García-Caro Núñez
Arrow right icon
View More author details
Toc

Events


Events are basically callbacks from GUI elements that allow us to write custom user actions. When using a GUI library, such as Windows Forms or Windows Presentation Foundation (WPF), events are part of the GUI classes. We can add custom behavior by adding a listener to these events. For example, if we want to handle the click event of a button in a login form, we can write a listener code for the Click event of that Login button.

Events in F# are first-class citizens, which means that they are exposed as a type IEvent<'T> that are composable using the Events module. Let's take a look at declaring events and using them, and then dive into using event processing in GUI programming.

Declaring events

Events are created using the F# Event<'T> class, which is a wrapper implementation around the .NET eventing system. It has the following two functions:

  • Publish: This is used to expose the event
  • Trigger: This triggers or raises the event with the arguments

The following piece of code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at £16.99/month. Cancel anytime