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:
  1. let tabcontrolobjvariable=new TabControl()  
For example:
  1. 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:
  1. Let tabpageobjvariable=new TabPage()  
For example:
  1. 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 “:

  1. // Learn more about F# at http://fsharp.net  
  2. //use the F# library  
  3. open System  
  4. //use the drawing classes  
  5. open System.Drawing  
  6. //specifies the location of the form class  
  7. open System.Windows.Forms  
  8. //specifies the font face and style  
  9. let ffont=new Font("Arial", 9.75F,FontStyle.Italic, GraphicsUnit.Point)  
  10. //creates a form  
  11. let tabform=new Form(Text="Use TabControl",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font,ClientSize=new System.Drawing.Size(250,250),FormBorderStyle=FormBorderStyle.FixedSingle)  
  12. //creates a tab control set its TabSizeMode to fixed  
  13. let tabcontrol=new TabControl(SizeMode=TabSizeMode.Fixed,Location=new System.Drawing.Point(20, 20),Size=new System.Drawing.Size(214, 192))  
  14. //creates a new tab page  
  15. let page1=new TabPage(Text="First Tab",Cursor=Cursors.Hand)  
  16. //creates a new label  
  17. let page1label=new Label(Text="This is page1",Font=ffont,Location=new System.Drawing.Point(20, 20))  
  18. //creates another tab page  
  19. let page2=new TabPage(Text="Second Tab",Cursor=Cursors.Hand)  
  20. //creates another label  
  21. let page2label=new Label(Text="This is page2",Font=ffont,Location=new System.Drawing.Point(20, 20))  
  22. //adds the tabcontrol to our form  
  23. tabform.Controls.Add(tabcontrol)  
  24. //adds the tab pages to our tab control  
  25. tabcontrol.Controls.Add(page1)  
  26. //adds the label to the first page  
  27. page1.Controls.Add(page1label)  
  28. //adds the second page to our tab control  
  29. tabcontrol.Controls.Add(page2)  
  30. //adds the second label to our tab control  
  31. page2.Controls.Add(page2label)  
  32. tabform.Show()  
  33. //executes our application  
  34. Application.Run(tabform)  

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