Display MessageBox on Button Click Event in FSharp

  • A K
  • A K
  • Updated date, Oct 12, 2011
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#