TabControl(Visual F#)

TabControl is a control that can be used to organize information. It can be utilized as a good alternative to menustrip control. To Create a TabControl in Visual F#, use the folowing syntax:
let tabcontrolobjvariable=new TabControl()
For example:
let tabcontrol=new TabControl()
To add a page to your tab control, use the Create an object from the TabPage class using the following syntax:
Let tabpageobjvariable=new TabPage()
For example:
Let tabpage=new TabPage()
For a simple example on using TabControl, follow these steps:

1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008.
2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category.
3. Click the Project menu>Add reference>Click the .Net tab>Locate then double-click System.Windows.Forms. Do step 3 again and this time, select System.Drawing from the .Net tab.
4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:

// Learn more about F# at http://fsharp.net
//use the F# library
open System
//use the drawing classes
open System.Drawing
//specifies the location of the form class
open System.Windows.Forms
//specifies the font face and style
let ffont=new Font("Arial", 9.75F,FontStyle.Italic, GraphicsUnit.Point)
//creates a form
let tabform=new Form(Text="Use TabControl",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font,ClientSize=new System.Drawing.Size(250,250),FormBorderStyle=FormBorderStyle.FixedSingle)
//creates a tab control set its TabSizeMode to fixed
let tabcontrol=new TabControl(SizeMode=TabSizeMode.Fixed,Location=new System.Drawing.Point(20, 20),Size=new System.Drawing.Size(214, 192))
//creates a new tab page
let page1=new TabPage(Text="First Tab",Cursor=Cursors.Hand)
//creates a new label
let page1label=new Label(Text="This is page1",Font=ffont,Location=new System.Drawing.Point(20, 20))
//creates another tab page
let page2=new TabPage(Text="Second Tab",Cursor=Cursors.Hand)
//creates another label
let page2label=new Label(Text="This is page2",Font=ffont,Location=new System.Drawing.Point(20, 20))
//adds the tabcontrol to our form
tabform.Controls.Add(tabcontrol)
//adds the tab pages to our tab control
tabcontrol.Controls.Add(page1)
//adds the label to the first page
page1.Controls.Add(page1label)
//adds the second page to our tab control
tabcontrol.Controls.Add(page2)
//adds the second label to our tab control
page2.Controls.Add(page2label)
tabform.Show()
//executes our application
Application.Run(tabform)

5. Click the run icon to execute your application. You should now see an output similar to the following screen shot:

Property Grid Control(Visual F#)

A property grid cotrol is a control used to display the properties associated to an object. To make a property grid control, use the following syntax:
Let propertygridobjvariable=new PropertyGrid()
For example:
let props=new PropertyGrid()
One of the important property is the SelectedObject property which defines the name of the object from which the grid control will get its returned properties. The syntax for SelectedObject property is:
Propertygridvariable.SelectedObject<-Objvariable
For example:
Props.SelectedObject<-button
For the sake of example, follow these steps: 1. Click Start>All Programs>Microsoft Visual Studio 2008>Microsoft Visual Studio 2008. 2. Click File>New>Project>Select Visual F# in the project types>Select F# application in the Visual Studio installed templates category. 3. Click the Project menu>Add reference>Click the .Net tab>Locate then double-click System.Windows.Forms. Do step 3 again and this time, select System.Drawing from the .Net tab. 4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:
// Learn more about F# at http://fsharp.net
//use the F# library
open System
//use the drawing class. Enables intellisense
open System.Drawing
//use the form class
open System.Windows.Forms
//creates a new form
let myform=new Form(Text="Use Process Grid",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)
//creates a textbox
let txtbox=new TextBox(Text="Textbox", Location=new System.Drawing.Point(5, 240))
//creates a label
let lbl=new Label(Text="Label", Location=new System.Drawing.Point(120, 240),AutoSize=true,BorderStyle=BorderStyle.FixedSingle)
//make a button from the button class
let button=new Button(Text="Button", Location=new System.Drawing.Point(200, 240))
//make a property grid control
let props=new PropertyGrid(Size=new System.Drawing.Size(180, 220),Left=50)
//adds a descriptive label
let desc=new Label(Text="Click the control below to view its properties...",AutoSize=true,Top=220)
//add the controls to our form
myform.Controls.Add(txtbox)
myform.Controls.Add(lbl)
myform.Controls.Add(button)
myform.Controls.Add(props)
myform.Controls.Add(desc)
//when the txtbox is clicked,display its properties in the property grid
txtbox.Click.Add(fun txtprops->props.SelectedObject<-txtbox)
//when the label is clicked,display its properties in the property grid
lbl.Click.Add(fun txtprops->props.SelectedObject<-lbl)
//when the button is clicked,display its properties in the property grid
button.Click.Add(fun txtprops->props.SelectedObject<-button)
myform.Show()
//executes our application
Application.Run(myform)

5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: