Adding space to a concatenated String

There are several ways to add space to a contanated string in Visual F#:

1.Using the Tab Escape Character

Syntax:
“text1” + “\t” + “textn”

For instance:
Trace.WriteLine("Adding" +”\t”+ “Space”)

This will display “Adding Space” with 5-6 spaces in between in the output window. You can also use the unicode equivalent of tab which is \u0009. For example:
Trace.WriteLine("Adding" +”\u0009”+ “Space”)
2. Typing a space or “ “ between the concatenated strings
Syntax:
“text1” + “ ” + “textn”

For instance:
Trace.WriteLine("Adding" +” ”+ “Space”)
You can also use the unicode equivalent of space which is \u0032. For example:
Trace.WriteLine("Adding" +”\u0032”+ “Space”)
3. Using the Convert.ToChar() string manipulation function
Convert.ToChar converts a specified key code to character.
The key code for tab is 9 while Spacebar has 32.

Syntax:
Convert.ToChar(key code)
Examples:
//backspace key
Trace.WriteLine(Convert.ToString(Convert.ToChar(8)))
//enter key
Trace.WriteLine(Convert.ToString(Convert.ToChar(13)))
//adds space to a concatenated string
Trace.WriteLine(“Adding” + Convert.ToString(Convert.ToChar(32)) + “Space” )

For a simple example of application that adds space to a concatenated string:

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
//specifies the namespace memory location of the classes that
//will be used in our application
open System
open System.Diagnostics
open System.Windows.Forms
open System.Drawing
//creates our form
let myform= new Form(Text="Adding Space")
//creates our controls  
let label1=new Label(Text="Firstname:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Lastname:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let fnametextbox=new TextBox(Location=new System.Drawing.Point(100,10),BorderStyle=BorderStyle.FixedSingle)
let lnametextbox=new TextBox(Location=new System.Drawing.Point(100,50),BorderStyle=BorderStyle.FixedSingle)
let okbutton=new Button(Text="Ok", Location=new System.Drawing.Point(120, 170))
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(200, 170))
myform.Controls.Add(label1)
myform.Controls.Add(label2
myform.Controls.Add(fnametextbox)
myform.Controls.Add(lnametextbox)
myform.Controls.Add(okbutton)
myform.Controls.Add(exitbutton)
myform.Click.Add(fun space->
//display our text in the ouput window
Trace.WriteLine("Adding Spaces")
Trace.WriteLine(label1.Text + "\u0009" + fnametextbox.Text)
Trace.WriteLine(label2.Text + "\u0009" + lnametextbox.Text))

//execute our application
myform.Show()
Application.Run(myform)

Gradient and Textured Form in Visual F#

To create a gradient form in Visual F#, simply use a gradient brush and use that brush to draw a rectangle that will cover the whole form area. To create a LinearGradientBrush, use the following syntax:
let newbrush=new LinearGradientBrush(brushpoint,color1,color2,strokeangle)
For instance:
let newbrush=new LinearGradientBrush(rect,Color.Green,Color.YellowGreen,45.0F)
Follow these steps to create a gradient form using the LinearGradientBrush drawing method:

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
//specifies the namespace memory location of the classes that
//will be used in our application
open System
open System.Windows.Forms
open System.Drawing
open System.Drawing.Drawing2D
//creates our form
let myform= new Form(Text="Add Gradient Background")
//create a rectangle
//change its upper left x and y coordinates to 0,0
//sets it width and height to the width and height of the form
let rect=new Rectangle(0,0,myform.Width,myform.Height)
//creates a gradient brush
let newbrush=new LinearGradientBrush(rect,Color.Green,Color.YellowGreen,45.0F)
//paints our form with a solid and filled rectangle
myform.Paint.Add(fun fillrect->fillrect.Graphics.FillRectangle(newbrush,rect)) 
//executes our application
myform.Show()
Application.Run(myform)

This will display the following output:



To create a textured form, use a TextureBrush to draw a rectangle that will cover the whole form area then display that rectangle on your form.

For instance:
// Learn more about F# at http://fsharp.net
//specifies the namespace memory location of the classes that
//will be used in our application
open System
open System.Windows.Forms
open System.Drawing
open System.Drawing.Drawing2D

//creates our form
let myform= new Form(Text="Add Textured Background")
//draws a rectangle with the same width and height as our form
let drawrect=new Rectangle(0,0,myform.Width,myform.Height)
//creates a texturedbrush using a windows default image
//tile the image Vertically and Horizontally
let newbrush=new TextureBrush(new Bitmap("C:\Windows\Zapotec.bmp"),WrapMode=WrapMode.TileFlipXY)
//applies the brush in drawing our rectangle
myform.Paint.Add(fun fillrect->fillrect.Graphics.FillRectangle(newbrush, drawrect)) 
//executes our application
myform.Show()
Application.Run(myform)

Add navigational buttons to a database application without using a BindingNavigator

On my previous post, we were able to add a navigational button to our application by using a BindingNavigator, today, we will do everything manually. To add a navigational button by hand, all you need to do is to bind your controls using this method and increment or decrement the Row index number to navigate around your records. This method is slightly similar to the methods used by most developers in adding navigational buttons to VB.net database applications.

For the sake of example, follow these steps(I assume here that you have already created a database file named “dbEmployee” and a table named “tblEmployee”):

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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
open System.Data.OleDb
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\Administrator\My Documents\dbEmployee.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", oleconn)
let deletecommand=new System.Data.OleDb.OleDbCommand()

//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Add Navigational Buttons Manually",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(200, 170))  
let label1=new Label(Text="Employee number:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Firstname:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let label3=new Label(Text="Lastname:",Location=new System.Drawing.Point(0,100),AutoSize=true)
let emplabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let fnamelabel=new Label(Location=new System.Drawing.Point(100,50),BorderStyle=BorderStyle.FixedSingle)
let lnamelabel=new Label(Location=new System.Drawing.Point(100,100),BorderStyle=BorderStyle.FixedSingle)
let topbutton=new Button(Text="Top", Location=new System.Drawing.Point(40, 170))
let bottombutton=new Button(Text="Bottom", Location=new System.Drawing.Point(120, 170))
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(exitbutton)
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(label3)
dataform.Controls.Add(emplabel)
dataform.Controls.Add(fnamelabel)
dataform.Controls.Add(lnamelabel)
dataform.Controls.Add(topbutton)
dataform.Controls.Add(bottombutton)

//binds the fieldnames to our label
emplabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(0))
fnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(1))
lnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(2))

//when the topbutton is clicked
//assigns 0 rowindexnumber value causing the 
//first record to be displayed
topbutton.Click.Add(fun top->
emplabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(0))
fnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(1))
lnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(2)))

//when the bottombutton is clicked
//assign the index number of the last row as a rowindexnumer
//since we only have two records on our table
//so the index number of the last row is understood to be 1
//when manipulating large number of records, i suggest using
//dataset11.Tables.["tblEmployee"].Rows.Count() to
//automatically count the number of records

bottombutton.Click.Add(fun bottom->
emplabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(1).Item(0))
fnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(1).Item(1))
lnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(1).Item(2)))

//when the exit button is clicked
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
                    dataform.Close()
                    oleconn.Close())

//executes our application
dataform.Show()
Application.Run(dataform)

5. This will display the following output:



6. Simple...right?

Yet another way of binding a control to a field name in Visual F#

On my last post, I’ve shown you how to bind a record value to a control using the DataBindings method. Another way of binding a control to a fieldname is by using Text property of a control and assigning the dataset collection properties as its value:

Syntax:

controlobjvariable.Text<- (datasetname.Tables.["tablename"].Rows.Item(rowindexnumber).Item(columnindexnumber))
For instance:
emplabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(0))
The rowindexnumber of the first record on your table is 0, the second record is 1 and so on. Same goes with the columnindexnumber. For a simple example of application that uses the binding method above, follow these steps(I assume here that you have already created a database file named “dbEmployee” and a table named “tblEmployee”):
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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
open System.Data.OleDb
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\Administrator\My Documents\dbEmployee.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", oleconn)
let deletecommand=new System.Data.OleDb.OleDbCommand()

//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Bind Form Control Part 2",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 170))  
let label1=new Label(Text="Employee number:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Firstname:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let label3=new Label(Text="Lastname:",Location=new System.Drawing.Point(0,100),AutoSize=true)
let emplabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let fnamelabel=new Label(Location=new System.Drawing.Point(100,50),BorderStyle=BorderStyle.FixedSingle)
let lnamelabel=new Label(Location=new System.Drawing.Point(100,100),BorderStyle=BorderStyle.FixedSingle)
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(exitbutton)
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(label3)
dataform.Controls.Add(emplabel)
dataform.Controls.Add(fnamelabel)
dataform.Controls.Add(lnamelabel)

//binds the fieldnames to our label
emplabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(0))
fnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(1))
lnamelabel.Text<-Convert.ToString(dataset11.Tables.["tblEmployee"].Rows.Item(0).Item(2))

//when the exit button is clicked
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
                    dataform.Close()
                    oleconn.Close())

//executes our application
dataform.Show()
Application.Run(dataform)
5. This will display the following output:

Manipulating an Image Data in Visual F#

To manipulate an image data, simply add an oleobject fieldname on your table and insert a bitmap image to it. To display the image on your form, use a picturebox control then bind your oleobject fieldname to it using the following syntax:
Pictureboxobjname.DataBindings.Add(new Binding(pictureboxproperty,datasource,fieldname))
For instance:
appico.DataBindings.Add(new Binding("Image",bindingsource,"oleapplogo",true))
The last boolean parameter enables the control formatting. We also use the Image property instead of the usual Text for the fact that it is the property used to display an image on your form.

Before proceding to the steps below, I want you to make an Ms-Access 2003 or 2007 database file named “dbApplication”. Create a table inside it and name it “tblApplication”. Use the following specifications:



Chrappname Text Handles the application name
Oleapplogo OLE Object Handles the application ico

After creating your table, you can add appropriate values to it for instance:




chrappname oleapplogo
PHP Bitmap Image
Apache Bitmap Image

Bitmap Image refers the the Bitmap Object that you have inserted using the Paste From Ms-Paint command.

After creating the table and adding appropriate values to it.We are now ready for our sample application. Just 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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\station 2\My Documents\dbApplication.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblApplication", oleconn)
//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblApplication")|>ignore
//creates a form
let dataform = new Form(Text="Manipulate Image Data",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls  
let label1=new Label(Text="App. name:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Icon:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let appnamelabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let appico=new PictureBox(SizeMode=PictureBoxSizeMode.StretchImage,Location=new System.Drawing.Point(140,50))

let bindingsource=new BindingSource()
//creates a binding navigator
//this will allow us to add navigational buttons to our data grid
let bindingnav=new BindingNavigator(Dock=DockStyle.None,Location=new System.Drawing.Point(100, 170))
//creates a toolstrip buttons for our binding navigator
let movefirst=new ToolStripButton(Text="Top")
let moveprev=new ToolStripButton(Text="Prev")
let movenext=new ToolStripButton(Text="Next")
let movelast=new ToolStripButton(Text="Bottom")
let exitbutton=new ToolStripButton(Text="Exit")
//adds the toolstripbuttons to our binding navigator
bindingnav.Items.Add(movefirst)|>ignore
bindingnav.Items.Add(moveprev)|>ignore
bindingnav.Items.Add(movenext)|>ignore
bindingnav.Items.Add(movelast)|>ignore
bindingnav.Items.Add(exitbutton)|>ignore
//adds a function to each buttons
bindingnav.MoveFirstItem<-movefirst
bindingnav.MoveNextItem<-movenext
bindingnav.MovePreviousItem<-moveprev
bindingnav.MoveLastItem<-movelast
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
                    dataform.Close()
                    oleconn.Close())
//assigns the dataset name as a bindingsource datasource
bindingsource.DataSource<-dataset11
//assigns our table as a binding source datamember
bindingsource.DataMember<-"tblApplication"
//assigns the bindingsource name as a binding navigators
//bindingsource value
bindingnav.BindingSource<-bindingsource
//opens the connection
oleconn.Open()
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(appnamelabel)
dataform.Controls.Add(appico)

dataform.Controls.Add(bindingnav)
//binds the fieldnames to our label
appnamelabel.DataBindings.Add(new Binding("Text",bindingsource,"chrappname"))
appico.DataBindings.Add(new Binding("Image",bindingsource,"oleapplogo",true))
//executes our application
dataform.Show()
Application.Run(dataform)
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: 6. Here’s another version of the code above without BindingSource and BindingNavigator.
// Learn more about F# at http://fsharp.net
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\station 2\My Documents\dbApplication.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblApplication", oleconn)
//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblApplication")|>ignore
//creates a form
let dataform = new Form(Text="Manipulate Image Data",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls  
let label1=new Label(Text="App. name:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Icon:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let appnamelabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let appico=new PictureBox(SizeMode=PictureBoxSizeMode.StretchImage,Location=new System.Drawing.Point(140,50))
//opens the connection
oleconn.Open()
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(appnamelabel)
dataform.Controls.Add(appico)
//binds the fieldnames to our label
appnamelabel.DataBindings.Add(new Binding("Text",dataset11,"tblApplication.chrappname"))
appico.DataBindings.Add(new Binding("Image",dataset11,"tblApplication.oleapplogo",true))
//executes our application
dataform.Show()
Application.Run(dataform)
For more sketchy tutorials on Visual F# visit Microsoft F# Developer Center.

Adding navigational Buttons to your database application

The fastest way to add navigational buttons to your database application is to use a BindingNavigator. If you are not yet familiar with Binding Navigator, I suggest reading this post first before proceeding to the steps below:

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:

Field NameData Type Description
chrempno text Handles employee id
chrfnametext Handles employee’s name
chrlname text Holds employee’s last name


After designing the structure of your table, you can enter appropriate values for each field. For instance:

chrempnochrfnameChrlname
1John Doe
2Jean Doe


Now that we are done creating a table, we can now link to it by using OleDbDataAdapter in Visual F#:


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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\station 2\My Documents\dbEmployee.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", oleconn)
//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Add Navigational Buttons",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls  
let label1=new Label(Text="Employee number:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Firstname:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let label3=new Label(Text="Lastname:",Location=new System.Drawing.Point(0,100),AutoSize=true)
let emplabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let fnamelabel=new Label(Location=new System.Drawing.Point(100,50),BorderStyle=BorderStyle.FixedSingle)
let lnamelabel=new Label(Location=new System.Drawing.Point(100,100),BorderStyle=BorderStyle.FixedSingle)
let bindingsource=new BindingSource()
//creates a binding navigator
//this will allow us to add navigational buttons to our data grid
let bindingnav=new BindingNavigator(Dock=DockStyle.None,Location=new System.Drawing.Point(100, 170))
//creates a toolstrip buttons for our binding navigator
let movefirst=new ToolStripButton(Text="Top")
let moveprev=new ToolStripButton(Text="Prev")
let movenext=new ToolStripButton(Text="Next")
let movelast=new ToolStripButton(Text="Bottom")
let exitbutton=new ToolStripButton(Text="Exit")
//adds the toolstripbuttons to our binding navigator
bindingnav.Items.Add(movefirst)|>ignore
bindingnav.Items.Add(moveprev)|>ignore
bindingnav.Items.Add(movenext)|>ignore
bindingnav.Items.Add(movelast)|>ignore
bindingnav.Items.Add(exitbutton)|>ignore
//adds a function to each buttons
bindingnav.MoveFirstItem<-movefirst
bindingnav.MoveNextItem<-movenext
bindingnav.MovePreviousItem<-moveprev
bindingnav.MoveLastItem<-movelast
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
                    dataform.Close()
                    oleconn.Close())
//assigns the dataset name as a bindingsource datasource
bindingsource.DataSource<-dataset11
//assigns our table as a binding source datamember
bindingsource.DataMember<-"tblEmployee"
//assigns the bindingsource name as a binding navigators
//bindingsource value
bindingnav.BindingSource<-bindingsource
//opens the connection
oleconn.Open()
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(label3)
dataform.Controls.Add(emplabel)
dataform.Controls.Add(fnamelabel)
dataform.Controls.Add(lnamelabel)
dataform.Controls.Add(bindingnav)
//binds the fieldnames to our label
emplabel.DataBindings.Add(new Binding("Text",bindingsource,"chrempno"))
fnamelabel.DataBindings.Add(new Binding("Text",bindingsource,"chrfname"))
lnamelabel.DataBindings.Add(new Binding("Text",bindingsource,"chrlname"))
//executes our application
dataform.Show()
Application.Run(dataform)
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: For more sketchy tutorials on Visual F# visit Microsoft F# Developer Center.

BindingSource and BindingNavigator(OleDbDataAdapter Visual F#)

BindingSource allows us to simplify the binding process to our control. To create a binding source in Visual F#, use the following syntax:
let bindingsourceobjname=new BindingSource()
for instance:
let bindingsource=new BindingSource()
The two most important properties of BindingSource component are DataSource which specifies the data source of the bindingsource, and the Datamember which specifies the specific table to which your bindingsource is bound to.

BindingNavigator are simply used to add navigational buttons to your database application. The syntax in creating a binding source is:
let bindingnavigatorobjvariable=new BindingNavigator()
for instance:
let bindingnav=new BindingNavigator()
One of the essential properties of the BindingNavigator component is the BindingSource which specifies the bindingsource name to which the BindingNavigator is bound to.

Follow these steps for a simple example on using binding navigator:

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:

Field NameData Type Description
chrempno text Handles employee id
chrfnametext Handles employee’s name
chrlname text Holds employee’s last name


After designing the structure of your table, you can enter appropriate values for each field. For instance:

chrempnochrfnameChrlname
1John Doe
2Jean Doe


Now that we are done creating a table, we can now link to it by using OleDbDataAdapter in Visual F#:


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 and System.Data 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
//specifies the location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a connection object
let olecon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\Administrator\My Documents\dbEmployee.mdb")
//adds an oleDbDataAdapter
let dataadapter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", olecon)
//generate a dataset
let dataset11 = new DataSet()
//fill our dataset with record values
dataadapter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Change DataGrid Header",ClientSize=new System.Drawing.Size(398, 232))
//creates a datagrid
let datagrid = new DataGridView(ColumnHeadersHeightSizeMode=DataGridViewColumnHeadersHeightSizeMode.AutoSize,Size=new System.Drawing.Size(341, 143),Location=new System.Drawing.Point(22, 38))
//creates a binding source to simplify the binding process
let bindingsource=new BindingSource()
//creates a binding navigator
//this will allow us to add navigational buttons to our data grid
let bindingnav=new BindingNavigator()
//creates a toolstrip buttons for our binding navigator
let movefirst=new ToolStripButton(Text="Top")
let moveprev=new ToolStripButton(Text="Prev")
let movenext=new ToolStripButton(Text="Next")
let movelast=new ToolStripButton(Text="Bottom")
//adds the toolstripbuttons to our binding navigator
bindingnav.Items.Add(movefirst)|>ignore
bindingnav.Items.Add(moveprev)|>ignore
bindingnav.Items.Add(movenext)|>ignore
bindingnav.Items.Add(movelast)|>ignore
//adds a function to each buttons
bindingnav.MoveFirstItem<-movefirst
bindingnav.MoveNextItem<-movenext
bindingnav.MovePreviousItem<-moveprev
bindingnav.MoveLastItem<-movelast
//assigns the dataset name as a bindingsource datasource
bindingsource.DataSource<-dataset11
//assigns our table as a binding source datamember
bindingsource.DataMember<-"tblEmployee"
//assigns the bindingsource name as a binding navigators
//bindingsource value
bindingnav.BindingSource<-bindingsource
//opens the connection
olecon.Open()
//adds the controls to our form
dataform.Controls.Add(bindingnav)
datagrid.DataSource <- bindingsource

//add the datagrid to our form
dataform.Controls.Add(datagrid)
//execute our application
dataform.Show()
Application.Run(dataform)
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: For more sketchy tutorials on Visual F# visit Microsoft F# Developer Center.

Changing the DataGridView Header Text in Visual F#

To change the header text of a grid contrl in Visual F#, the first thing that you’ll need to do is to create a grid view columns. This can be done by using the following syntax:
let columnname=new DataGridViewTextBoxColumn()
For instance:
let chrempnocol=new DataGridViewTextBoxColumn()
After that, you’ll need to add that column to the data grid. This can be done by using the following syntax:
dataobjvariable.Columns.Add(columnname)
For example:
datagrid.Columns.Add(chrempnocol)
Then finally, you’ll need to bind the column name to the fieldname where you will be getting the record value followed by changing its header text using the DataPropertyName and HeaderText propeties.

For a simple example on changing the header text of a grid control, follow these steps:

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:

Field NameData Type Description
chrempno text Handles employee id
chrfnametext Handles employee’s name
chrlname text Holds employee’s last name


After designing the structure of your table, you can enter appropriate values for each field. For instance:

chrempnochrfnameChrlname
1John Doe
2Jean Doe


Now that we are done creating a table, we can now link to it by using OleDbDataAdapter in Visual F#:


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 and System.Data 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
//specifies the location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a connection object
let olecon = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\Administrator\My Documents\dbEmployee.mdb")
//adds an oleDbDataAdapter
let dataadapter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", olecon)
//generate a dataset
let dataset11 = new DataSet()
//fill our dataset with record values
dataadapter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Change DataGrid Header",ClientSize=new System.Drawing.Size(398, 232))
//creates a datagrid
let datagrid = new DataGridView(ColumnHeadersHeightSizeMode=DataGridViewColumnHeadersHeightSizeMode.AutoSize,Size=new System.Drawing.Size(341, 143),Location=new System.Drawing.Point(22, 38))
//creates a grid control colums
let chrempnocol=new DataGridViewTextBoxColumn()
let chrfnamecol=new DataGridViewTextBoxColumn()
let chrlnamecol=new DataGridViewTextBoxColumn()
//adds the columns into our datagrid
datagrid.Columns.Add(chrempnocol)|>ignore
datagrid.Columns.Add(chrfnamecol)|>ignore
datagrid.Columns.Add(chrlnamecol)|>ignore
//opens the database connection and
//set our table as the datagrid's datasource
olecon.Open()
datagrid.DataSource <- dataset11.Tables.["tblEmployee"]
//links our fieldname to each grid
//and change its header text
chrempnocol.DataPropertyName<-"chrempno"
chrempnocol.HeaderText<-"Employee No."
chrfnamecol.DataPropertyName<-"chrfname"
chrfnamecol.HeaderText<-"First Name"
chrlnamecol.DataPropertyName<-"chrlname"
chrlnamecol.HeaderText<-"Last Name"
//add the datagrid to our form
dataform.Controls.Add(datagrid)
//execute our application
dataform.Show()
Application.Run(dataform)
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot:
For more sketchy tutorials on Visual F# visit Microsoft F# Developer Center.That's all for now:)

Binding a Record Value To a Control (OleDbDataAdapter Visual F#)

To bind a record value to a control, simply use the DataBindings method of the control which has the following syntax:

controlobjvariable.DataBindings.Add(new Binding(controlproperty, datasetname, fieldname))
For instance:

fnamelabel.DataBindings.Add(new Binding("Text", dataset11, "Table1.fname", true))
For a simple data binding example, follow these steps:

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:

Field NameData Type Description
chrempno text Handles employee id
chrfnametext Handles employee’s name
chrlname text Holds employee’s last name


After designing the structure of your table, you can enter appropriate values for each field. For instance:

chrempnochrfnameChrlname
2010AJohn Doe
2010BJean Doe


Now that we are done creating a table, we can now link to it by using OleDbDataAdapter in Visual F#:


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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Regular, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
  Data Source=C:\Documents and Settings\station 2\My Documents\dbEmployee.mdb")
 //creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", oleconn)
//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Use OleDbDataAdapter",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates our controls
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 170))  
let label1=new Label(Text="Employee number:",Location=new System.Drawing.Point(0, 10),AutoSize=true)
let label2=new Label(Text="Firstname:",Location=new System.Drawing.Point(0, 50),AutoSize=true)
let label3=new Label(Text="Lastname:",Location=new System.Drawing.Point(0,100),AutoSize=true)
let emplabel=new Label(Location=new System.Drawing.Point(140,10),BorderStyle=BorderStyle.FixedSingle)
let fnamelabel=new Label(Location=new System.Drawing.Point(100,50),BorderStyle=BorderStyle.FixedSingle)
let lnamelabel=new Label(Location=new System.Drawing.Point(100,100),BorderStyle=BorderStyle.FixedSingle)
//assings the font to our form
dataform.Font<-ffont
//adds the controls to our form
dataform.Controls.Add(exitbutton)
dataform.Controls.Add(label1)
dataform.Controls.Add(label2)
dataform.Controls.Add(label3)
dataform.Controls.Add(emplabel)
dataform.Controls.Add(fnamelabel)
dataform.Controls.Add(lnamelabel)
//binds the fieldnames to our label
emplabel.DataBindings.Add(new Binding("Text",dataset11,"tblEmployee.chrempno"))
fnamelabel.DataBindings.Add(new Binding("Text",dataset11,"tblEmployee.chrfname"))
lnamelabel.DataBindings.Add(new Binding("Text",dataset11,"tblEmployee.chrlname"))
//when the exit button is clicked
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
                    dataform.Close()
                    oleconn.Close())

//executes our application
dataform.Show()
Application.Run(dataform)

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

Linking to an Ms-Access DataSource using OledbDataAdapter in Visual F#

To link to an Ms-Access data source, the first thing that you’ll need to do is to create an object variable based on the OleDbConnection class. OleDbConnection specifies the name of the Data Provider and the Location of the database file that you wish to link to. To create an OleDbConnection object use the following syntax:
let Oledbconnectionobjvariable = new System.Data.OleDb.OleDbConnection("Provider=DataProviderName;
Data Source=Url and filename of the database file")
For instance:
let Oledbconnectionobjvariable = new System.Data.OleDb.OleDbConnection("Provider= Microsoft.Jet.OLEDB.4.0;
Data Source=C:\Mydatabasefile.mdb")
Microsoft.Jet.OLEDB.4.0 is a data provider used to link to Ms-Access 2003 or higher database files.
After creating an OledbConnectionObject, the next thing that you’ll need to do is to add an OleDbDataAdapter control, to specify how the data will be displayed on your form and the information about the connection. This can be done by using the following syntax:
let oledbdataadapterobjvariable= new System.Data.OleDb. OleDbDataAdapter("SQL statement", ConnectionString)
ConnectionString refers to the information about the connection and is saved in the Oledbconnection object.

Lastly, youll need to create a storage location for your table values. This can be done by creating a Dataset. To create a dataset, use the following syntax:
Let Datasetobjvariable=new Dataset()
For a simple example on using OleDbDataAdapter to an AccessDataSource, follow these steps:

Before the Database Connection and Binding process I want you to make an Ms-Access database file named “dbEmployee” containing a table named “tblEmployee”. Use the following specifications:

Field NameData Type Description
chrempno text Handles employee id
chrfnametext Handles employee’s name
chrlname text Holds employee’s last name


After designing the structure of your table, you can enter appropriate values for each field. For instance:

chrempnochrfnameChrlname
2010AJohn Doe
2010BJean Doe


Now that we are done creating a table, we can now link to it by using OleDbDataAdapter in Visual F#:


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 and System.Data 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
//specifies the memory location of the class files
//that will be needed in our application
open System
open System.Windows.Forms
open System.Data
open System.Drawing
//creates a font
let ffont=new Font("Verdana", 9.75F,FontStyle.Italic, GraphicsUnit.Point)  
//creates a connection object
let oleconn = new System.Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;
Data Source=C:\Documents and Settings\station 2\My Documents\dbEmployee.mdb")
//creates an OleDbDataAdapter
let dataadpter = new System.Data.OleDb.OleDbDataAdapter("Select * from tblEmployee", oleconn)
//generates a dataset
let dataset11 = new DataSet()
//fills the dataset with recod values
dataadpter.Fill(dataset11,"tblEmployee")|>ignore
//creates a form
let dataform = new Form(Text="Use OleDbDataAdapter",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 200),StartPosition=FormStartPosition.CenterScreen)
//creates an exit button
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 170))  
//creates a gridview control
let datagrid = new DataGridView(Dock=DockStyle.None)
//opens the connection to the datasource
oleconn.Open()
//assign our table
//as a datagrid datasource
datagrid.DataSource <- dataset11.Tables.["tblEmployee"]
//add the controls to our form
dataform.Font<-ffont
dataform.Controls.Add(datagrid)
dataform.Controls.Add(exitbutton)
//when the exit button is clicked
exitbutton.Click.Add(fun exit->
//close the form and dataconnection
dataform.Close()
oleconn.Close())

//executes our application
dataform.Show()
Application.Run(dataform)


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


Wrapping the contents submitted from a textarea in PHP

By default, the texts submitted from a textarea in PHP are displayed in an unbroken single line. For instance, if you have entered the following lorem ipsum text:



It will be displayed as:



This simply tells us that PHP ignores the breaklines posted from a textarea control. This glitch cannot be solved by simply using the WRAP attribute of the textarea tag. Fortunately, PHP provide us with several string functions that can use to solve this problem. One of these functions is the wordwrap function which wraps text depending on the number of character specified by the user. The wordwrap function has the following syntax:

wordwrap(“text to wrap”, columnwidth ,breakline);
For instance:

wordwrap(“Hello world”,5,"<br/>")
For a sample usage of wordwrap in solving the textarea wrapping problem, follow these steps:

1. Start your text editor (Notepad, Notepad++, or Programmers Notepad).
2. Enter the following:

<HTML>
<body>

<!--if the submit button is not yet clicked-->
<?php
if(!$_POST['Submitted'])
:
?>

<!--display our form-->
<FORM ACTION="<?php echo $_SERVER['PHP_SELF']; ?>" Method="POST" >
<br/>
  Enter your message:<br>
<TEXTAREA  WRAp="hard" ROWS="8" COLS="30" NAME="usermsg"></TEXTAREA><br>
<INPUT TYPE="Submit" VALUE="Submit" Name="Submitted"></INPUT> <INPUT TYPE="Reset" VALUE="Clear">
</FORM>


</BODY>
</HTML>


<!--otherwise-->
<?php
else
:
?>


<!--display the text from the textarea-->
<?php
$msg=$_POST['usermsg'];
$wrapmsg=wordwrap($msg,30,"<br/>");
echo "$msg";
endif;
?>
?>

3. Save it as sample.php in the htdocs folder.
4. Launch your web browser.
5. Type the following in the address bar:
http://localhost/sample.php
6. You should now see the following:



7. Try entering a long text in the textarea to see the wordwrap effect. For more information on using the wordwrap string function visit http://www.php.net. That's all!

Changing the Pointer when the mouse hovers an object(Visual F#)

To change the mouse pointer when the mouse hovers an object, use the Cursor property. All form controls in Visual F# has Cursor property. To use the Cursor property, use the following syntax:
Objectvariable.Cursor<-Cursors.CursorStyle
For example:
exitbutton.Cursor<-Cursors.UpArrow
Some CursorStyles values are NoMove2D,Cross and PanSouth. To understand the usage of the Cursor property, try the following example: 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
//specify the namespace memory location
//of the classes that will be needed in our application
open System
open System.Drawing
open System.Windows.Forms
//create our controls
let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
let myform=new Form(Text="Use Cursors",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(207, 133),StartPosition=FormStartPosition.CenterScreen)
let llabel1=new Label(Text="Hand Cursor",AutoSize=true,Location=new System.Drawing.Point(20, 80))
let llabel2=new Label(Text="AppStarting Cursor",AutoSize=true,Location=new System.Drawing.Point(120,80))
//add the controls into our form
myform.Controls.Add(llabel1)
myform.Controls.Add(llabel2)
//add a mousehover and mouseleave events to our controls
//when the mouse hovers our labels, its cursor style,forecolor, and font size will change
//when the mouse leaves our control, the cursor style, label forecolor, and font size will
//return back to default
llabel1.MouseHover.Add(fun disphandcursor->
                  llabel1.ForeColor<-Color.Red
                  llabel1.Cursor<-Cursors.Hand
                  let ffont=new System.Drawing.Font("Microsoft Sans Serif",12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
                  llabel1.Font<-ffont)
llabel1.MouseLeave.Add(fun changefontsize->
                  llabel1.ForeColor<-Color.Empty
                  let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
                  llabel1.Font<-ffont)
llabel2.MouseHover.Add(fun dispappcursor->
                  llabel2.ForeColor<-Color.Red
                  llabel2.Cursor<-Cursors.AppStarting
                  let ffont=new System.Drawing.Font("Microsoft Sans Serif",12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
                  llabel2.Font<-ffont)
llabel2.MouseLeave.Add(fun retainsfontsize->
                  llabel2.ForeColor<-Color.Empty
                  let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)
                  llabel2.Font<-ffont)              
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:

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: