Creating Window Form Application in FSharp

Posted by A K Articles | F# October 12, 2011
In this article I have explained how to create a Window Form Application in F#.
Reader Level:

Introduction: For creating a Windows Form in F#, we add the System.Windows.Form namespace to our application. All the sets of classes are found in System.Windows.Form.dll. These classes are used to create window forms and controls. Now we create a window form by following several steps which are given below.

Step 1: We open Visual Studio and take a F# Application. We give a name to our application, like the below figure.

window form in f#

Step 2: The Application page will open as below.


Step 3: Now, we go to solution Explorer and right Click on References as below.

window form in f#

Step 4: We Click on Add Reference. A new window will open with the caption Add Reference

window form in f#

Step 5: We Click on .NET and select System.Drawing and System.Windows.Form and Click on ok button. Figure is given below

window form in f#

Step 6: We write the following code.

open System

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


The above code will be written in Program.fs. We note that I have given the form a name by assigning form name ("My Window Application") to form.Text and Background color as Gray.

Step 7: We run the application by pressing Ctrl+F5 key. The output will look like below:

window form in f#

Employers - Post Free Jobs