ARTICLE

Creating Window Form Application in FSharp

Posted by Alok Harsh 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.

 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#

Login to add your contents and source code to this article
post comment
     
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts