F# leverages the .NET platform and GUI programming is no exception. All classes from the .NET platform are available in this section. We will concentrate on the one from the System.Windows.Forms
namespace.
It's possible to use the same code from F# Interactive and modify the GUI on the fly. We will look at this in more detail in the Displaying data section.
Let's look at an example where we make use of a .NET form and a button. The button will be connected to an event handler called for every click on the button. As you can see when you read the code, event handlers are higher-order functions that result in a clean and compact code.
open System.Windows.Forms let form = new Form(Text = "First F# form") let button = new Button(Text = "Click me to close!", Dock = DockStyle.Fill) button.Click.Add(fun _ -> Application.Exit() |> ignore) form.Controls.Add(button) form.Show()
The screenshot for the output of the preceding code is as follows: