Display MessageBox on Button Click Event in FSharp

Here we will learn to show MessageBox on Button Click in FSharp.

Write the following code.

open
System
open
System.Windows.Forms
open
System.Drawing

let form=new Form()
form.Text<-
"My Window Application"
form.BackColor <-Color.Gray
 

let
btn=new Button()
btn.Text<-
"Click"
btn.BackColor<- Color.Green

btn.Click.Add(fun a-> MessageBox.Show("Hi") |>ignore)

form.Controls.Add(btn)
Application.Run(form)


Then run the application. The output will be look like below figure.

messagebox in f#

When We Click on Button, MessageBox is displayed with message "Hi". Like below figure.

messagebox in f#