November 12, 2007

F# Windows Forms Tutorial

Here's a little tutorial on how to show a windows form from F# (The new .NET Language)

You can get the compiler from here

open System
open System.Windows.Forms

let form = new Form()
do form.Width <- 300
do form.Height <- 300
do form.FormBorderStyle <- FormBorderStyle.Fixed3D
do form.Text <- "Windows Form from F#"

let RichTextbox1 = new RichTextBox()
do RichTextbox1.Text <- "Hello Windows Forms From F#"
do RichTextbox1.Size <- new System.Drawing.Size(320,240)

let btn1 = new Button()
do btn1.Text <- "Click me!"
do btn1.Location <- new System.Drawing.Point(0,240)
let btn1Click (e: #IEvent<_>) = e.Add(fun _ -> System.Windows.Forms.MessageBox.Show("Hello World, from btnClick event handler!");())

do btn1Click btn1.Click

do form.Controls.Add(RichTextbox1)
do form.Controls.Add(btn1)

do Application.Run(form)

Back to Home


  1. Just one slight clarification,

    F# is not a new .NET language. the fact that it is now offically included in the CLR is new.

    Otherwise great post!


Note: Only a member of this blog may post a comment.