Creating Window Form Application in FSharp


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.

 step2.gif

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
open
System.Windows.Forms
open
System.Drawing
 

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

Application.Run(form)

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#

Up Next
    Ebook Download
    View all
    Learn
    View all