Home

Introduction

 

Fundamentals

 

Introduction

 

 

     
 
 

 

   
   
 

Previous Copyright © 2015 FunctionX Next

Home

Inheritance and Windows Controls

 

Fundamentals of Controls Inheritance

 

Introduction

As you should know already, inheritance consists of creating a class that is based on another class. Windows controls support inheritance. This means means that you can create a class for a new control so that the class would derive from the class of an existing control. At a minimum, start the class with the type keyword. Use the inherit keyword to specify the control on which the new class is derived. Here is an example:

open System
open System.Windows.Forms

type Exercise() =
    inherit Form()

After creating the class, you can use it. You can declare a variable for it and use it. If the class is for a form, you can pass the variable to the Application.Run() method. Here is an example:

open System
open System.Windows.Forms

type Exercise() =
    inherit Form()

let exo = new Exercise()

[<EntryPoint>]
let main argv =
    Application.Run exo
    0

This would produce:

Fundamentals of Controls Inheritance

In the above example, we declared the vairable outside of the main() function. Otherwise, you can declare the variable in that function. Here is an example:

open System
open System.Windows.Forms

type Exercise() =
    inherit Form()

[<EntryPoint>]
let main argv =
    let exo = new Exercise()
    Application.Run exo
    0

Every Windows control have properties and each property has a default variable. After inheriting a class from a control, the new class has access to all properties and (public) methods of the class of the control. If you declare a variable for the new class, you can specify the desired values for the properties of your choice. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type Exercise() =
    inherit Form()

[<EntryPoint>]
let main argv =
    let exo = new Exercise()

    exo.MaximizeBox <- false
    exo.Text <- "Exercise"
    exo.ClientSize <- new System.Drawing.Size(225, 150)
    exo.StartPosition <- FormStartPosition.CenterScreen

[<EntryPoint>]
let main argv =
    Application.Run exo
    0

This would produce:

Fundamentals of Controls Inheritance

Remember that in some cases, you don't have to declare a variable. You can directly instantiate it where its object would be used. Here is an example:

open System
open System.Windows.Forms

type Exercise() =
    inherit Form()

[<EntryPoint>]
let main argv =
    Application.Run(new Exercise())
    0

Adding New Methods

Class inheritance primarily consists of customizing the behavior of an existing class. To add an action to a class, you can create a method in the inherited class. You can use such a method to modify the primary characteristics of the parent class. If the method is created as public member, you can access it from a variable of the class. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type Exercise() =
    inherit Form()

    member this.Create() =
        this.MaximizeBox <- false
        this.Text <- "Road System Database"
        this.ClientSize <- new System.Drawing.Size(225, 150)
        this.StartPosition <- FormStartPosition.CenterScreen

let exo = new Exercise()
exo.Create()

[<EntryPoint>]
let main argv =    
    Application.Run exo
    0

The Microsoft Visual Studio standards suggest that a control's class use a (private) method named initializeComponent. You can use such a method to initialize the class. Here is an example:

type Exercise(caption) as this =
    inherit Form()

    let initializeComponent() =
        this.MaximizeBox <- false
        this.Text <- "Road System Database"
        this.ClientSize <- new System.Drawing.Size(225, 150)
        this.StartPosition <- FormStartPosition.CenterScreen

The constructors in F# don't behave like in other languages. For example, they don't have a body. Or rather the whole body of a class is considered the conditional body of a constructor. Based on this, if you create a do section, it would execute as soon as an object of the class is created. You can use such a do section to call a method whose behavior must execute immediately. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type Exercise() as this =
    inherit Form()

    let initializeComponent() =
        this.MaximizeBox <- false
        this.Text <- "Road System Database"
        this.ClientSize <- new System.Drawing.Size(225, 150)
        this.StartPosition <- FormStartPosition.CenterScreen

    do
        initializeComponent()

[<EntryPoint>]
let main argv =    
    Application.Run(new Exercise())
    0

If the inherited class is for a control container such as a form and you want it to host one or more controls, you can declare their variables in the body of the class but initialize them in the initializeComponent() method. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation() as this =
    inherit Form()

    let lblNewPassword : Label = new Label()
    let txtNewPassword : TextBox = new TextBox()
    let txtPasswordLength : TextBox = new TextBox()
    let lblPasswordLength : Label = new Label()
    let lblConfirmPassword : Label = new Label()
    let txtConfirmPassword : TextBox = new TextBox()
    let txtLowercaseLetters : TextBox = new TextBox()
    let lblLowercaseLetters : Label = new Label()
    let txtUppercaseLetters : TextBox = new TextBox()
    let lblUppercaseLetters : Label = new Label()
    let txtDigits : TextBox = new TextBox()
    let lblDigits : Label = new Label()
    let txtSymbols : TextBox = new TextBox()
    let lblSymbols : Label = new Label()
    let lblMessage : Label = new Label()
    let btnSubmit : Button = new Button()
    let btnClose : Button = new Button()

    let initializeComponent() =
        // Label: New Password
        lblNewPassword.Location <- new Point(12, 22)
        lblNewPassword.AutoSize <- true
        lblNewPassword.Text <- "New Password:"
        this.Controls.Add lblNewPassword
        
        // Text Box: New Password
        txtNewPassword.Location <- new Point(112, 19)
        txtNewPassword.Width <- 124
        this.Controls.Add txtNewPassword

        // Text Box: Password Length
        txtPasswordLength.Location <- new Point(242, 19)
        txtPasswordLength.Width <- 20
        this.Controls.Add txtPasswordLength

        // Label: Password Length
        lblPasswordLength.Location <- new Point(267, 22)
        lblPasswordLength.AutoSize <- true
        lblPasswordLength.Text <- "Characters"
        this.Controls.Add lblPasswordLength

        // Label: Confirm Password
        lblConfirmPassword.Location <- new Point(12, 51)
        lblConfirmPassword.AutoSize <- true
        lblConfirmPassword.Text <- "Confirm Password:"
        this.Controls.Add lblConfirmPassword
        
        // Label: Confirm Password
        txtConfirmPassword.Location <- new Point(112, 48)
        txtConfirmPassword.Width <- 124
        this.Controls.Add txtConfirmPassword

        // Text Box: Lowercase Letters
        txtLowercaseLetters.Location <- new Point(112, 78)
        txtLowercaseLetters.Width <- 20
        this.Controls.Add txtLowercaseLetters

        // Label: Lowercase Letters
        lblLowercaseLetters.Location <- new Point(136, 81)
        lblLowercaseLetters.AutoSize <- true
        lblLowercaseLetters.Text <- "Lowercase Letters"
        this.Controls.Add lblLowercaseLetters

        // Text Box: Uppercase Letters
        txtUppercaseLetters.Location <- new Point(242, 78)
        txtUppercaseLetters.Width <- 20
        this.Controls.Add txtUppercaseLetters

        // Label: Uppercase Letters
        lblUppercaseLetters.Location <- new Point(266, 81)
        lblUppercaseLetters.AutoSize <- true
        lblUppercaseLetters.Text <- "Uppercase Letters"
        this.Controls.Add lblUppercaseLetters

        // Text Box: Digits
        txtDigits.Location <- new Point(112, 108)
        txtDigits.Width <- 20
        this.Controls.Add txtDigits
        
        // Label: Digits
        lblDigits.Location <- new Point(136, 111)
        lblDigits.AutoSize <- true
        lblDigits.Text <- "Digits"
        this.Controls.Add lblDigits

        // Text Box: Symbols
        txtSymbols.Location <- new Point(242, 111)
        txtSymbols.Width <- 20
        this.Controls.Add txtSymbols

        // Label: Symbols
        lblSymbols.Location <- new Point(266, 114)
        lblSymbols.AutoSize <- true
        lblSymbols.Text <- "Symbols"
        this.Controls.Add lblSymbols

        // Label: Message
        lblMessage.Location <- new Point(109, 182)
        lblMessage.AutoSize <- true
        this.Controls.Add lblMessage

        // Button: Submit
        btnSubmit.Location <- new Point(112, 146)
        btnSubmit.Width <- 75
        btnSubmit.Text <- "Submit"
        this.Controls.Add btnSubmit

        // Button: Close
        btnClose.Location <- new Point(193, 146)
        btnClose.Text <- "Close"
        this.Controls.Add btnClose

        this.MaximizeBox <- false
        this.Text <- "Create Passrod"
        this.ClientSize <- new System.Drawing.Size(385, 210)
        this.StartPosition <- FormStartPosition.CenterScreen
    do
        initializeComponent()

[<EntryPoint>]
let main argv =    
    Application.Run(new PasswordEvaluation())
    0

Implementing an Event

Windows controls have events used to perform actions at specific occurrences. In the body of a derived a class, you can create a method for each event and pass that method to the Add() method of the control. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation() as this =
    inherit Form()

    let lblNewPassword : Label = new Label()
    let txtNewPassword : TextBox = new TextBox()
    let txtPasswordLength : TextBox = new TextBox()
    let lblPasswordLength : Label = new Label()
    let lblConfirmPassword : Label = new Label()
    let txtConfirmPassword : TextBox = new TextBox()
    let txtLowercaseLetters : TextBox = new TextBox()
    let lblLowercaseLetters : Label = new Label()
    let txtUppercaseLetters : TextBox = new TextBox()
    let lblUppercaseLetters : Label = new Label()
    let txtDigits : TextBox = new TextBox()
    let lblDigits : Label = new Label()
    let txtSymbols : TextBox = new TextBox()
    let lblSymbols : Label = new Label()
    let lblMessage : Label = new Label()
    let btnSubmit : Button = new Button()
    let btnClose : Button = new Button()

    let txtNewPasswordTextChanged e =
        let mutable digits = 0
        let mutable symbols = 0
        let mutable lowercaseLetters = 0
        let mutable uppercaseLetters = 0
        let length = txtNewPassword.Text.Length

        for i = 0 to length - 1 do
            if Char.IsDigit(txtNewPassword.Text.[i]) then
                digits <- digits + 1
            if Char.IsSymbol(txtNewPassword.Text.[i]) || Char.IsPunctuation(txtNewPassword.Text.[i]) then
                symbols <- symbols + 1
            if Char.IsLower(txtNewPassword.Text, i) then
                lowercaseLetters <- lowercaseLetters + 1
            if Char.IsUpper(txtNewPassword.Text, i) then
                uppercaseLetters <- uppercaseLetters + 1
    
        txtDigits.Text <- string digits
        txtSymbols.Text <- string symbols
        txtLowercaseLetters.Text <- string lowercaseLetters
        txtUppercaseLetters.Text <- string uppercaseLetters

        txtPasswordLength.Text <- string length

    let btnSubmitClick e =
        let strNewPassword = txtNewPassword.Text
        let strConfirmPassword = txtConfirmPassword.Text

        if (strNewPassword = strConfirmPassword) = false then
            lblMessage.Text <- "The passwords are different"
        else
            lblMessage.Text <- ""

    let btnCloseClick e =
        this.Close()

    let initializeComponent() =			
        // Label: New Password
        lblNewPassword.Location <- new Point(12, 22)
        lblNewPassword.AutoSize <- true
        lblNewPassword.Text <- "New Password:"
        this.Controls.Add lblNewPassword
        
        // Text Box: New Password
        txtNewPassword.Location <- new Point(112, 19)
        txtNewPassword.Width <- 124
        txtNewPassword.TextChanged.Add txtNewPasswordTextChanged
        this.Controls.Add txtNewPassword

        // Text Box: Password Length
        txtPasswordLength.Location <- new Point(242, 19)
        txtPasswordLength.Width <- 20
        this.Controls.Add txtPasswordLength

        // Label: Password Length
        lblPasswordLength.Location <- new Point(267, 22)
        lblPasswordLength.AutoSize <- true
        lblPasswordLength.Text <- "Characters"
        this.Controls.Add lblPasswordLength

        // Label: Confirm Password
        lblConfirmPassword.Location <- new Point(12, 51)
        lblConfirmPassword.AutoSize <- true
        lblConfirmPassword.Text <- "Confirm Password:"
        this.Controls.Add lblConfirmPassword
        
        // Label: Confirm Password
        txtConfirmPassword.Location <- new Point(112, 48)
        txtConfirmPassword.Width <- 124
        this.Controls.Add txtConfirmPassword

        // Text Box: Lowercase Letters
        txtLowercaseLetters.Location <- new Point(112, 78)
        txtLowercaseLetters.Width <- 20
        this.Controls.Add txtLowercaseLetters

        // Label: Lowercase Letters
        lblLowercaseLetters.Location <- new Point(136, 81)
        lblLowercaseLetters.AutoSize <- true
        lblLowercaseLetters.Text <- "Lowercase Letters"
        this.Controls.Add lblLowercaseLetters

        // Text Box: Uppercase Letters
        txtUppercaseLetters.Location <- new Point(242, 78)
        txtUppercaseLetters.Width <- 20
        this.Controls.Add txtUppercaseLetters

        // Label: Uppercase Letters
        lblUppercaseLetters.Location <- new Point(266, 81)
        lblUppercaseLetters.AutoSize <- true
        lblUppercaseLetters.Text <- "Uppercase Letters"
        this.Controls.Add lblUppercaseLetters

        // Text Box: Digits
        txtDigits.Location <- new Point(112, 108)
        txtDigits.Width <- 20
        this.Controls.Add txtDigits
        
        // Label: Digits
        lblDigits.Location <- new Point(136, 111)
        lblDigits.AutoSize <- true
        lblDigits.Text <- "Digits"
        this.Controls.Add lblDigits

        // Text Box: Symbols
        txtSymbols.Location <- new Point(242, 111)
        txtSymbols.Width <- 20
        this.Controls.Add txtSymbols

        // Label: Symbols
        lblSymbols.Location <- new Point(266, 114)
        lblSymbols.AutoSize <- true
        lblSymbols.Text <- "Symbols"
        this.Controls.Add lblSymbols

        // Label: Message
        lblMessage.Location <- new Point(109, 182)
        lblMessage.AutoSize <- true
        this.Controls.Add lblMessage

        // Button: Submit
        btnSubmit.Location <- new Point(112, 146)
        btnSubmit.Width <- 75
        btnSubmit.Text <- "Submit"
        btnSubmit.Click.Add btnSubmitClick
        this.Controls.Add btnSubmit

        // Button: Close
        btnClose.Location <- new Point(193, 146)
        btnClose.Text <- "Close"
        btnClose.Click.Add btnCloseClick
        this.Controls.Add btnClose

        this.MaximizeBox <- false
        this.Text <- "Create Passrod"
        this.ClientSize <- new System.Drawing.Size(385, 210)
        this.StartPosition <- FormStartPosition.CenterScreen
    do
        initializeComponent()

[<EntryPoint>]
let main argv =    
    Application.Run(new PasswordEvaluation())
    0

Here is an example of running the program:

Equality of Two Strings

Equality of Two Strings

Equality of Two Strings

In the above code, we first defined some methods for the events of Windows controls. Using a lambda expression, you can directly implement the event where the control is defined. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation() as this =
    inherit Form()

    let lblNewPassword : Label = new Label()
    let txtNewPassword : TextBox = new TextBox()
    let txtPasswordLength : TextBox = new TextBox()
    let lblPasswordLength : Label = new Label()
    let lblConfirmPassword : Label = new Label()
    let txtConfirmPassword : TextBox = new TextBox()
    let txtLowercaseLetters : TextBox = new TextBox()
    let lblLowercaseLetters : Label = new Label()
    let txtUppercaseLetters : TextBox = new TextBox()
    let lblUppercaseLetters : Label = new Label()
    let txtDigits : TextBox = new TextBox()
    let lblDigits : Label = new Label()
    let txtSymbols : TextBox = new TextBox()
    let lblSymbols : Label = new Label()
    let lblMessage : Label = new Label()
    let btnSubmit : Button = new Button()
    let btnClose : Button = new Button()

    let initializeComponent() =
        // Label: New Password
        lblNewPassword.Location <- new Point(12, 22)
        lblNewPassword.AutoSize <- true
        lblNewPassword.Text <- "New Password:"
        this.Controls.Add lblNewPassword
        
        // Text Box: New Password
        txtNewPassword.Location <- new Point(112, 19)
        txtNewPassword.Width <- 124
        txtNewPassword.TextChanged.Add(fun e ->
            let mutable digits = 0
            let mutable symbols = 0
            let mutable lowercaseLetters = 0
            let mutable uppercaseLetters = 0
            let length = txtNewPassword.Text.Length

            for i = 0 to length - 1 do
                if Char.IsDigit(txtNewPassword.Text.[i]) then
                    digits <- digits + 1
                if Char.IsSymbol(txtNewPassword.Text.[i]) || Char.IsPunctuation(txtNewPassword.Text.[i]) then
                    symbols <- symbols + 1
                if Char.IsLower(txtNewPassword.Text, i) then
                    lowercaseLetters <- lowercaseLetters + 1
                if Char.IsUpper(txtNewPassword.Text, i) then
                    uppercaseLetters <- uppercaseLetters + 1
    
            txtDigits.Text <- string digits
            txtSymbols.Text <- string symbols
            txtLowercaseLetters.Text <- string lowercaseLetters
            txtUppercaseLetters.Text <- string uppercaseLetters

            txtPasswordLength.Text <- string length)
        this.Controls.Add txtNewPassword

        // Text Box: Password Length
        txtPasswordLength.Location <- new Point(242, 19)
        txtPasswordLength.Width <- 20
        this.Controls.Add txtPasswordLength

        // Label: Password Length
        lblPasswordLength.Location <- new Point(267, 22)
        lblPasswordLength.AutoSize <- true
        lblPasswordLength.Text <- "Characters"
        this.Controls.Add lblPasswordLength

        // Label: Confirm Password
        lblConfirmPassword.Location <- new Point(12, 51)
        lblConfirmPassword.AutoSize <- true
        lblConfirmPassword.Text <- "Confirm Password:"
        this.Controls.Add lblConfirmPassword
        
        // Label: Confirm Password
        txtConfirmPassword.Location <- new Point(112, 48)
        txtConfirmPassword.Width <- 124
        this.Controls.Add txtConfirmPassword

        // Text Box: Lowercase Letters
        txtLowercaseLetters.Location <- new Point(112, 78)
        txtLowercaseLetters.Width <- 20
        this.Controls.Add txtLowercaseLetters

        // Label: Lowercase Letters
        lblLowercaseLetters.Location <- new Point(136, 81)
        lblLowercaseLetters.AutoSize <- true
        lblLowercaseLetters.Text <- "Lowercase Letters"
        this.Controls.Add lblLowercaseLetters

        // Text Box: Uppercase Letters
        txtUppercaseLetters.Location <- new Point(242, 78)
        txtUppercaseLetters.Width <- 20
        this.Controls.Add txtUppercaseLetters

        // Label: Uppercase Letters
        lblUppercaseLetters.Location <- new Point(266, 81)
        lblUppercaseLetters.AutoSize <- true
        lblUppercaseLetters.Text <- "Uppercase Letters"
        this.Controls.Add lblUppercaseLetters

        // Text Box: Digits
        txtDigits.Location <- new Point(112, 108)
        txtDigits.Width <- 20
        this.Controls.Add txtDigits
        
        // Label: Digits
        lblDigits.Location <- new Point(136, 111)
        lblDigits.AutoSize <- true
        lblDigits.Text <- "Digits"
        this.Controls.Add lblDigits

        // Text Box: Symbols
        txtSymbols.Location <- new Point(242, 111)
        txtSymbols.Width <- 20
        this.Controls.Add txtSymbols

        // Label: Symbols
        lblSymbols.Location <- new Point(266, 114)
        lblSymbols.AutoSize <- true
        lblSymbols.Text <- "Symbols"
        this.Controls.Add lblSymbols

        // Label: Message
        lblMessage.Location <- new Point(109, 182)
        lblMessage.AutoSize <- true
        this.Controls.Add lblMessage

        // Button: Submit
        btnSubmit.Location <- new Point(112, 146)
        btnSubmit.Width <- 75
        btnSubmit.Text <- "Submit"
        btnSubmit.Click.Add(fun e ->
            let strNewPassword = txtNewPassword.Text
            let strConfirmPassword = txtConfirmPassword.Text

            if (strNewPassword = strConfirmPassword) = false then
                lblMessage.Text <- "The passwords are different"
            else
                lblMessage.Text <- "")

        this.Controls.Add btnSubmit

        // Button: Close
        btnClose.Location <- new Point(193, 146)
        btnClose.Text <- "Close"
        btnClose.Click.Add(fun e -> this.Close())
        this.Controls.Add btnClose

        this.MaximizeBox <- false
        this.Text <- "Create Passrod"
        this.ClientSize <- new System.Drawing.Size(385, 220)
        this.StartPosition <- FormStartPosition.CenterScreen

    do
        initializeComponent()

[<EntryPoint>]
let main argv =    
    Application.Run(new PasswordEvaluation())
    0

Creating Constructors

When you are creating a class that derives from one for a Windows control, you can use the parameter-less default constructor as we have done so far. Otherwise, you can add parameters for the properties you are planning to change for your particular control. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation(caption, size, maxbox, position) as this =
    inherit Form()

    let lblNewPassword : Label = new Label()
    let txtNewPassword : TextBox = new TextBox()
    let txtPasswordLength : TextBox = new TextBox()
    let lblPasswordLength : Label = new Label()
    let lblConfirmPassword : Label = new Label()
    let txtConfirmPassword : TextBox = new TextBox()
    let txtLowercaseLetters : TextBox = new TextBox()
    let lblLowercaseLetters : Label = new Label()
    let txtUppercaseLetters : TextBox = new TextBox()
    let lblUppercaseLetters : Label = new Label()
    let txtDigits : TextBox = new TextBox()
    let lblDigits : Label = new Label()
    let txtSymbols : TextBox = new TextBox()
    let lblSymbols : Label = new Label()
    let lblMessage : Label = new Label()
    let btnSubmit : Button = new Button()
    let btnClose : Button = new Button()

    let initializeComponent() =
        // Label: New Password
        lblNewPassword.Location <- new Point(12, 22)
        lblNewPassword.AutoSize <- true
        lblNewPassword.Text <- "New Password:"
        this.Controls.Add lblNewPassword
        
        // Text Box: New Password
        txtNewPassword.Location <- new Point(112, 19)
        txtNewPassword.Width <- 124
        txtNewPassword.TextChanged.Add(fun e ->
            let mutable digits = 0
            let mutable symbols = 0
            let mutable lowercaseLetters = 0
            let mutable uppercaseLetters = 0
            let length = txtNewPassword.Text.Length

            for i = 0 to length - 1 do
                if Char.IsDigit(txtNewPassword.Text.[i]) then
                    digits <- digits + 1
                if Char.IsSymbol(txtNewPassword.Text.[i]) ||
                   Char.IsPunctuation(txtNewPassword.Text.[i]) then
                    symbols <- symbols + 1
                if Char.IsLower(txtNewPassword.Text, i) then
                    lowercaseLetters <- lowercaseLetters + 1
                if Char.IsUpper(txtNewPassword.Text, i) then
                    uppercaseLetters <- uppercaseLetters + 1
    
            txtDigits.Text <- string digits
            txtSymbols.Text <- string symbols
            txtLowercaseLetters.Text <- string lowercaseLetters
            txtUppercaseLetters.Text <- string uppercaseLetters

            txtPasswordLength.Text <- string length)
        this.Controls.Add txtNewPassword

        // Text Box: Password Length
        txtPasswordLength.Location <- new Point(242, 19)
        txtPasswordLength.Width <- 20
        this.Controls.Add txtPasswordLength

        // Label: Password Length
        lblPasswordLength.Location <- new Point(267, 22)
        lblPasswordLength.AutoSize <- true
        lblPasswordLength.Text <- "Characters"
        this.Controls.Add lblPasswordLength

        // Label: Confirm Password
        lblConfirmPassword.Location <- new Point(12, 51)
        lblConfirmPassword.AutoSize <- true
        lblConfirmPassword.Text <- "Confirm Password:"
        this.Controls.Add lblConfirmPassword
        
        // Label: Confirm Password
        txtConfirmPassword.Location <- new Point(112, 48)
        txtConfirmPassword.Width <- 124
        this.Controls.Add txtConfirmPassword

        // Text Box: Lowercase Letters
        txtLowercaseLetters.Location <- new Point(112, 78)
        txtLowercaseLetters.Width <- 20
        this.Controls.Add txtLowercaseLetters

        // Label: Lowercase Letters
        lblLowercaseLetters.Location <- new Point(136, 81)
        lblLowercaseLetters.AutoSize <- true
        lblLowercaseLetters.Text <- "Lowercase Letters"
        this.Controls.Add lblLowercaseLetters

        // Text Box: Uppercase Letters
        txtUppercaseLetters.Location <- new Point(242, 78)
        txtUppercaseLetters.Width <- 20
        this.Controls.Add txtUppercaseLetters

        // Label: Uppercase Letters
        lblUppercaseLetters.Location <- new Point(266, 81)
        lblUppercaseLetters.AutoSize <- true
        lblUppercaseLetters.Text <- "Uppercase Letters"
        this.Controls.Add lblUppercaseLetters

        // Text Box: Digits
        txtDigits.Location <- new Point(112, 108)
        txtDigits.Width <- 20
        this.Controls.Add txtDigits
        
        // Label: Digits
        lblDigits.Location <- new Point(136, 111)
        lblDigits.AutoSize <- true
        lblDigits.Text <- "Digits"
        this.Controls.Add lblDigits

        // Text Box: Symbols
        txtSymbols.Location <- new Point(242, 111)
        txtSymbols.Width <- 20
        this.Controls.Add txtSymbols

        // Label: Symbols
        lblSymbols.Location <- new Point(266, 114)
        lblSymbols.AutoSize <- true
        lblSymbols.Text <- "Symbols"
        this.Controls.Add lblSymbols

        // Label: Message
        lblMessage.Location <- new Point(109, 182)
        lblMessage.AutoSize <- true
        this.Controls.Add lblMessage

        // Button: Submit
        btnSubmit.Location <- new Point(112, 146)
        btnSubmit.Width <- 75
        btnSubmit.Text <- "Submit"
        btnSubmit.Click.Add(fun e ->
            let strNewPassword = txtNewPassword.Text
            let strConfirmPassword = txtConfirmPassword.Text

            if (strNewPassword = strConfirmPassword) = false then
                lblMessage.Text <- "The passwords are different"
            else
                lblMessage.Text <- "")

        this.Controls.Add btnSubmit

        // Button: Close
        btnClose.Location <- new Point(193, 146)
        btnClose.Text <- "Close"
        btnClose.Click.Add(fun e -> this.Close())
        this.Controls.Add btnClose

        this.MaximizeBox <- maxbox
        this.Text <- caption
        this.ClientSize <- size
        this.StartPosition <- position

    do
        initializeComponent()

[<EntryPoint>]
let main argv =    
    Application.Run(new PasswordEvaluation("Password Evaluation",
                                           new System.Drawing.Size(385, 215),
                                           false, FormStartPosition.CenterScreen))
    0

If you do this, the properties you don't mention would use their default values.

Instead of one constructor, you can create as many constructors as you want, as long as you respect the rules for constructors in an F# class. Here is an example that uses two constructors:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation(caption, size, maxbox, position) as this =
    inherit Form()

    . . .

    new() = new PasswordEvaluation("",
    				   new System.Drawing.Size(385, 215),
    				   false, FormStartPosition.CenterScreen)

If you do this, when you declare a variable for the class, you can use either constructor. Here is an example that uses the parameter-less constructor:

[<EntryPoint>]
let main argv =
    Application.Run(new PasswordEvaluation())
    0

This would produce:

Creating Constructors

If you use the default constructor, you can access the desired properties and specify their values. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type PasswordEvaluation(caption, size, maxbox, position) as this =
    inherit Form()

    let lblNewPassword : Label = new Label()
    let txtNewPassword : TextBox = new TextBox()
    let txtPasswordLength : TextBox = new TextBox()
    let lblPasswordLength : Label = new Label()
    let lblConfirmPassword : Label = new Label()
    let txtConfirmPassword : TextBox = new TextBox()
    let txtLowercaseLetters : TextBox = new TextBox()
    let lblLowercaseLetters : Label = new Label()
    let txtUppercaseLetters : TextBox = new TextBox()
    let lblUppercaseLetters : Label = new Label()
    let txtDigits : TextBox = new TextBox()
    let lblDigits : Label = new Label()
    let txtSymbols : TextBox = new TextBox()
    let lblSymbols : Label = new Label()
    let lblMessage : Label = new Label()
    let btnSubmit : Button = new Button()
    let btnClose : Button = new Button()

    let initializeComponent() =
        // Label: New Password
        lblNewPassword.Location <- new Point(12, 22)
        lblNewPassword.AutoSize <- true
        lblNewPassword.Text <- "New Password:"
        this.Controls.Add lblNewPassword
        
        // Text Box: New Password
        txtNewPassword.Location <- new Point(112, 19)
        txtNewPassword.Width <- 124
        txtNewPassword.TextChanged.Add(fun e ->
            let mutable digits = 0
            let mutable symbols = 0
            let mutable lowercaseLetters = 0
            let mutable uppercaseLetters = 0
            let length = txtNewPassword.Text.Length

            for i = 0 to length - 1 do
                if Char.IsDigit(txtNewPassword.Text.[i]) then
                    digits <- digits + 1
                if Char.IsSymbol(txtNewPassword.Text.[i]) ||
                   Char.IsPunctuation(txtNewPassword.Text.[i]) then
                    symbols <- symbols + 1
                if Char.IsLower(txtNewPassword.Text, i) then
                    lowercaseLetters <- lowercaseLetters + 1
                if Char.IsUpper(txtNewPassword.Text, i) then
                    uppercaseLetters <- uppercaseLetters + 1
    
            txtDigits.Text <- string digits
            txtSymbols.Text <- string symbols
            txtLowercaseLetters.Text <- string lowercaseLetters
            txtUppercaseLetters.Text <- string uppercaseLetters

            txtPasswordLength.Text <- string length)
        this.Controls.Add txtNewPassword

        // Text Box: Password Length
        txtPasswordLength.Location <- new Point(242, 19)
        txtPasswordLength.Width <- 20
        this.Controls.Add txtPasswordLength

        // Label: Password Length
        lblPasswordLength.Location <- new Point(267, 22)
        lblPasswordLength.AutoSize <- true
        lblPasswordLength.Text <- "Characters"
        this.Controls.Add lblPasswordLength

        // Label: Confirm Password
        lblConfirmPassword.Location <- new Point(12, 51)
        lblConfirmPassword.AutoSize <- true
        lblConfirmPassword.Text <- "Confirm Password:"
        this.Controls.Add lblConfirmPassword
        
        // Label: Confirm Password
        txtConfirmPassword.Location <- new Point(112, 48)
        txtConfirmPassword.Width <- 124
        this.Controls.Add txtConfirmPassword

        // Text Box: Lowercase Letters
        txtLowercaseLetters.Location <- new Point(112, 78)
        txtLowercaseLetters.Width <- 20
        this.Controls.Add txtLowercaseLetters

        // Label: Lowercase Letters
        lblLowercaseLetters.Location <- new Point(136, 81)
        lblLowercaseLetters.AutoSize <- true
        lblLowercaseLetters.Text <- "Lowercase Letters"
        this.Controls.Add lblLowercaseLetters

        // Text Box: Uppercase Letters
        txtUppercaseLetters.Location <- new Point(242, 78)
        txtUppercaseLetters.Width <- 20
        this.Controls.Add txtUppercaseLetters

        // Label: Uppercase Letters
        lblUppercaseLetters.Location <- new Point(266, 81)
        lblUppercaseLetters.AutoSize <- true
        lblUppercaseLetters.Text <- "Uppercase Letters"
        this.Controls.Add lblUppercaseLetters

        // Text Box: Digits
        txtDigits.Location <- new Point(112, 108)
        txtDigits.Width <- 20
        this.Controls.Add txtDigits
        
        // Label: Digits
        lblDigits.Location <- new Point(136, 111)
        lblDigits.AutoSize <- true
        lblDigits.Text <- "Digits"
        this.Controls.Add lblDigits

        // Text Box: Symbols
        txtSymbols.Location <- new Point(242, 111)
        txtSymbols.Width <- 20
        this.Controls.Add txtSymbols

        // Label: Symbols
        lblSymbols.Location <- new Point(266, 114)
        lblSymbols.AutoSize <- true
        lblSymbols.Text <- "Symbols"
        this.Controls.Add lblSymbols

        // Label: Message
        lblMessage.Location <- new Point(109, 182)
        lblMessage.AutoSize <- true
        this.Controls.Add lblMessage

        // Button: Submit
        btnSubmit.Location <- new Point(112, 146)
        btnSubmit.Width <- 75
        btnSubmit.Text <- "Submit"
        btnSubmit.Click.Add(fun e ->
            let strNewPassword = txtNewPassword.Text
            let strConfirmPassword = txtConfirmPassword.Text

            if (strNewPassword = strConfirmPassword) = false then
                lblMessage.Text <- "The passwords are different"
            else
                lblMessage.Text <- "")

        this.Controls.Add btnSubmit

        // Button: Close
        btnClose.Location <- new Point(193, 146)
        btnClose.Text <- "Close"
        btnClose.Click.Add(fun e -> this.Close())
        this.Controls.Add btnClose

        this.MaximizeBox <- maxbox
        this.Text <- caption
        this.ClientSize <- size
        this.StartPosition <- position

    do
        initializeComponent()

    new() = new PasswordEvaluation("", new System.Drawing.Size(0, 0), false, FormStartPosition.Manual)

[<EntryPoint>]
let main argv =
    let pwdEval = new PasswordEvaluation()
    pwdEval.MinimizeBox <- false
    pwdEval.MaximizeBox <- false
    pwdEval.Text <- "Password Characteristics"
    pwdEval.ClientSize <- new System.Drawing.Size(370, 205)
    pwdEval.FormBorderStyle <- FormBorderStyle.FixedDialog
    pwdEval.StartPosition <- FormStartPosition.CenterScreen

    Application.Run pwdEval
    0
open System
open System.Windows.Forms

type Exercise =
    inherit Form

    new() = {}

[<EntryPoint>]
let main argv =    
    Application.Run (new Exercise())
    0

Inheritance and Type Definition

 

Introduction

Type definition can be used in control inheritance. Start the class with the type keyword. Use the inherit keyword to specify the control on which the new class is derived. Also, you must include the System.Drawing.dll library to your project. Here is an example:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

Creating Constructors

Type definition requires that you add a constructor that can be used to create objects. A constructor is created with new, empty parentheses, and the curly brackets assigned to it. This can be done as follows:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

Once this is done, you can declare a variable for the class and use that variable as you see fit. If the variable is for a form-based class,  you can pass it to the application. Here is an example:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

let payroll = new PayrollPreparation()

[<EntryPoint>]
let main argv = 
    Application.Run payroll
    0

This would produce:

Using the Application Class

In the same way, you can create as many constructors as you want, as longs as they have different signatures (such as different parameters).

Adding Methods

In order to perform actions on an object, you can add methods to a class. This is also valid for a derived class. Such methods can be created as member this. For a form, you can create a method that would be used to initialize some of the characteristics of the parent class. For a form, these would be the characteristics of the Form class. Here is an example:

type PayrollPreparation =
    inherit Form

    new() = {}

    member this.InitializeComponent() = ()

In the same way, you can create as many methods as you need. A method created as member this can be accessed from a variable of the class, outside the class. Here is an example:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

    member this.InitializeComponent() = ()

let payroll = new PayrollPreparation()

payroll.InitializeComponent()

[<EntryPoint>]
let main argv = 
    Application.Run payroll
    0

If you want, you can declare the variable in the main() function where it is needed. Here is an example:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

    member this.InitializeComponent() = ()

[<EntryPoint>]
let main argv =
    let payroll = new PayrollPreparation()

    payroll.InitializeComponent()

    Application.Run payroll
    0

In fact, if your class doesn't have members you need to access outside the class, that is if you don't need to access an instance of the class many times, then you don't need a variable of the class. You can just use the constructor where needed. Here is an example:

open System
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

[<EntryPoint>]
let main argv =
    Application.Run(new PayrollPreparation())
    0

Otherwise, if you create a method as member this, remember that it has access to the properties of the class. You can use such a method to initialize the properties. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    new() = {}

    member this.InitializeComponent() =
         this.MaximizeBox <- false
         this.Text <- "Payroll Preparation"
         this.ClientSize <- new System.Drawing.Size(300, 210)
         this.StartPosition <- FormStartPosition.CenterScreen

let payroll = new PayrollPreparation()
payroll.InitializeComponent()

[<EntryPoint>]
let main argv = 
    Application.Run payroll
    0

This would produce:

Payroll Preparation

Adding Windows Controls

If you need them, you can add Windows controls to your class. If your derived class doesn't use parentheses, the controls must be created with the val keyword. Such controls must be initialized in the curly brackets of the (a) constructor. To programmatically add the controls to the form, you can use a method of the class, such the InitializeComponent() method we created earlier. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type PayrollPreparation =
    inherit Form

    val lblHourlySalary : Label

    member this.InitializeComponent() =
         this.Controls.Add this.lblHourlySalary

    new() = { lblHourlySalary = new Label(Text = "Hourly Salary:") }

Once the control has been created, it can appear on the form and display to the user. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type  PayrollPreparation =
    inherit Form

    val lblHourlySalary : Label
    val txtHourlySalary : TextBox
    val lblTimeWorked   : Label
    val txtTimeWorked   : TextBox
    val btnPrepare      : Button
    val lblLine1        : Label
    val lblTime         : Label
    val lblPay          : Label
    val lblRegular      : Label
    val txtRegularTime  : TextBox
    val txtRegularPay   : TextBox
    val lblOvertime     : Label
    val txtOvertimeTime : TextBox
    val txtOvertimePay  : TextBox
    val lblLine2        : Label
    val lblGrossSalary  : Label
    val txtGrossSalary  : TextBox
    val btnClose        : Button

    member this.InitializeComponent() =
        this.Controls.Add this.lblHourlySalary
        this.Controls.Add this.txtHourlySalary
        this.Controls.Add this.lblTimeWorked
        this.Controls.Add this.txtTimeWorked
        this.Controls.Add this.btnPrepare
        this.Controls.Add this.lblLine1
        this.Controls.Add this.lblTime
        this.Controls.Add this.lblPay
        this.Controls.Add this.lblRegular
        this.Controls.Add this.txtRegularTime
        this.Controls.Add this.txtRegularPay
        this.Controls.Add this.lblOvertime
        this.Controls.Add this.txtOvertimeTime
        this.Controls.Add this.txtOvertimePay
        this.Controls.Add this.lblLine2
        this.Controls.Add this.lblGrossSalary
        this.Controls.Add this.txtGrossSalary
        this.Controls.Add this.btnClose

        this.MaximizeBox <- false
        this.Text <- "Payroll Preparation"
        this.ClientSize <- new System.Drawing.Size(300, 210)
        this.StartPosition <- FormStartPosition.CenterScreen

    new() = {
        lblHourlySalary = new Label(Text = "Hourly Salary:",
                                    AutoSize = true, Location = new Point(18, 22))
        txtHourlySalary = new TextBox(Size = new Size(75, 20),
                                      Location = new Point(115, 18), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblTimeWorked   = new Label(Text = "Time Worked:", AutoSize = true, Location = new Point(18, 48))
        txtTimeWorked   = new TextBox(Location = new Point(115, 45), Text = "0.00", TextAlign = HorizontalAlignment.Right, Size = new System.Drawing.Size(75, 20))
        btnPrepare      = new Button(Location = new Point(195, 43), Text = "Prepare")
        lblLine1        = new Label(Location = new Point(11, 68), Size = new System.Drawing.Size(385, 13),
                                    Text = "-----------------------------------------------------------------------")
        lblTime         = new Label(Location = new Point(107, 84), AutoSize = true, Text = "Time")
        lblPay          = new Label(Location = new Point(173, 84), AutoSize = true, Text = "Pay")
        lblRegular      = new Label(Location = new Point(18, 113), AutoSize = true, Text = "Regular:")
        txtRegularTime  = new TextBox(Location = new Point(110, 110), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        txtRegularPay   = new TextBox(Location = new Point(167, 110), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        txtOvertimeTime = new TextBox(Location = new Point(110, 136), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblOvertime     = new Label(Location = new Point(18, 134), AutoSize = true, Text = "Overtime:")
        txtOvertimePay  = new TextBox(Location = new Point(167, 136), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblLine2        = new Label(Location = new Point(11, 157), Size = new System.Drawing.Size(385, 13),
                                        Text = "-----------------------------------------------------------------------")
        lblGrossSalary  = new Label(Location = new Point(18, 178), AutoSize = true, Text = "Gross Salary:")
        txtGrossSalary  = new TextBox(Location = new Point(110, 175), Size = new System.Drawing.Size(70, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        btnClose = new Button(Left = 195, Top = 173, Text = "Close") }

let resto = new PayrollPreparation()

resto.InitializeComponent()

[<EntryPoint>]
let main argv =
    Application.Run resto
    0

This would produce:

Payroll Preparation

Also, once a control has been created in a type-defined form, the control can be accessed outside the class, from a variable of the class. Here is an example:

open System
open System.Drawing
open System.Windows.Forms

type Restaurant =
    inherit Form

    val lblTitle : Label
    val txtIntroduction : TextBox

    member this.InitializeComponent() =
        this.Controls.Add this.lblTitle
        this.Controls.Add this.txtIntroduction

        this.MaximizeBox <- false
        this.Text <- "Restaurant Presentation"
        this.ClientSize <- new System.Drawing.Size(320, 153)
        this.StartPosition <- FormStartPosition.CenterScreen

    new() = {
        lblTitle = new Label(Text = "Restaurant Introduction:",
                             AutoSize = true, Location = new Point(12, 12))
        txtIntroduction = new TextBox(Size = new Size(290, 100),
                                      Location = new Point(12, 36),
                                      Multiline = true)
        }

let resto = new Restaurant()
resto.txtIntroduction.Text <- "Welcome to Four-Corner restaurant. We serve the best exotic meals in the region. " +
                              "Our selection includes soups, sauce, meals, and appetizers. During the week, " +
                              "from Monday to Friday, we serve the Lunch Special when the prices of most of " +
                              "meals are reduced. Come and try our tastes. You will be delighted."

resto.InitializeComponent()

[<EntryPoint>]
let main argv = 
    Application.Run resto
    0

This would produce:

The Multi-Line Text Boxes

Implementing Events

Remember that you cannot use a let binding member in a type-defined class. Therefore, if you want to implement a control event, you can create it as a lambda expression as an argument to the Add() method of the desired event of the control. Here are examples:

open System
open System.Drawing
open System.Windows.Forms

type  PayrollPreparation =
    inherit Form

    val lblHourlySalary : Label
    val txtHourlySalary : TextBox
    val lblTimeWorked   : Label
    val txtTimeWorked   : TextBox
    val btnPrepare      : Button
    val lblLine1        : Label
    val lblTime         : Label
    val lblPay          : Label
    val lblRegular      : Label
    val txtRegularTime  : TextBox
    val txtRegularPay   : TextBox
    val lblOvertime     : Label
    val txtOvertimeTime : TextBox
    val txtOvertimePay  : TextBox
    val lblLine2        : Label
    val lblGrossSalary  : Label
    val txtGrossSalary  : TextBox
    val btnClose        : Button

    member this.InitializeComponent() =
        this.Controls.Add this.lblHourlySalary
        this.Controls.Add this.txtHourlySalary
        this.Controls.Add this.lblTimeWorked
        this.Controls.Add this.txtTimeWorked
        this.Controls.Add this.btnPrepare
        this.Controls.Add this.lblLine1
        this.Controls.Add this.lblTime
        this.Controls.Add this.lblPay
        this.Controls.Add this.lblRegular
        this.Controls.Add this.txtRegularTime
        this.Controls.Add this.txtRegularPay
        this.Controls.Add this.lblOvertime
        this.Controls.Add this.txtOvertimeTime
        this.Controls.Add this.txtOvertimePay
        this.Controls.Add this.lblLine2
        this.Controls.Add this.lblGrossSalary
        this.Controls.Add this.txtGrossSalary
        this.Controls.Add this.btnClose

        this.btnClose.Click.Add(fun e -> this.Close())
        this.btnPrepare.Click.Add(fun e ->
                            let hourlySalary = float this.txtHourlySalary.Text
                            let timeWorked = float this.txtTimeWorked.Text

                            let regularTime  = if timeWorked <= 40.00 then timeWorked else 40.00
                            let overtime     = if timeWorked <= 40.00 then 0.00 else timeWorked - 40.00
                            let regularPay   = if timeWorked <= 40.00 then hourlySalary * timeWorked else hourlySalary * 40.00
                            let overtimePay  = if timeWorked <= 40.00 then 0.00 else (timeWorked - 40.00) * hourlySalary * 1.50
                            let grossSalary  = regularPay + overtimePay

                            let strRegularTime = sprintf "%0.02f" regularTime
                            let strOvertime    = sprintf "%0.02f" overtime
                            let strRegularPay  = sprintf "%0.02f" regularPay
                            let strOvertimePay = sprintf "%0.02f" overtimePay
                            let strGrossSalary = sprintf "%0.02f" grossSalary
    
                            this.txtRegularTime.Text <- strRegularTime
                            this.txtRegularPay.Text  <- strRegularPay
                            this.txtOvertimeTime.Text <- strOvertime
                            this.txtOvertimePay.Text <- strOvertimePay
                            this.txtGrossSalary.Text  <- strGrossSalary)

        this.MaximizeBox <- false
        this.Text <- "Payroll Preparation"
        this.ClientSize <- new System.Drawing.Size(300, 210)
        this.StartPosition <- FormStartPosition.CenterScreen

    new() = {
        lblHourlySalary = new Label(Text = "Hourly Salary:",
                                    AutoSize = true, Location = new Point(18, 22))
        txtHourlySalary = new TextBox(Size = new Size(75, 20),
                                      Location = new Point(115, 18), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblTimeWorked   = new Label(Text = "Time Worked:", AutoSize = true, Location = new Point(18, 48))
        txtTimeWorked   = new TextBox(Location = new Point(115, 45), Text = "0.00", TextAlign = HorizontalAlignment.Right, Size = new System.Drawing.Size(75, 20))
        btnPrepare      = new Button(Location = new Point(195, 43), Text = "Prepare")
        lblLine1        = new Label(Location = new Point(11, 68), Size = new System.Drawing.Size(385, 13),
                                    Text = "-----------------------------------------------------------------------")
        lblTime         = new Label(Location = new Point(107, 84), AutoSize = true, Text = "Time")
        lblPay          = new Label(Location = new Point(173, 84), AutoSize = true, Text = "Pay")
        lblRegular      = new Label(Location = new Point(18, 113), AutoSize = true, Text = "Regular:")
        txtRegularTime  = new TextBox(Location = new Point(110, 110), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        txtRegularPay   = new TextBox(Location = new Point(167, 110), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        txtOvertimeTime = new TextBox(Location = new Point(110, 136), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblOvertime     = new Label(Location = new Point(18, 134), AutoSize = true, Text = "Overtime:")
        txtOvertimePay  = new TextBox(Location = new Point(167, 136), Size = new System.Drawing.Size(50, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        lblLine2        = new Label(Location = new Point(11, 157), Size = new System.Drawing.Size(385, 13),
                                        Text = "-----------------------------------------------------------------------")
        lblGrossSalary  = new Label(Location = new Point(18, 178), AutoSize = true, Text = "Gross Salary:")
        txtGrossSalary  = new TextBox(Location = new Point(110, 175), Size = new System.Drawing.Size(70, 20), Text = "0.00", TextAlign = HorizontalAlignment.Right)
        btnClose = new Button(Left = 195, Top = 173, Text = "Close") }

let resto = new PayrollPreparation()

resto.InitializeComponent()

[<EntryPoint>]
let main argv =
    Application.Run resto
    0

Here is an example of running the program:

Implementing Events Implementing Events

Home Copyright © 2014-2015, FunctionX Home