MonthCalendar Control(Visual F#)

MonthCalendar control is essentially used to display monthly calendar on your application. To make a month calendar control, follow the following syntax:
  1. Let calendarobjvariable=new MonthCalendar()  
Example:
  1. Let calendar=new MonthCalendar()  
For a simple example on using month calendar 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.

4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:

  1. //use the F# standard library  
  2. open System  
  3. open System.Drawing  
  4. open System.Windows.Forms   
  5. //sets the font face and font style of our calendar  
  6. let myfont=new Font("Arial",11.0f,FontStyle.Regular, GraphicsUnit.Point)  
  7. //create a form  
  8. let calendarform=new Form(Text="Use MonthCalendar",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)  
  9. //create a calendar object named calendar  
  10. //sets its minimum date to jan 1 1999   
  11. //set the maximum date displayed to it to Jan 1,8013  
  12. let calendar=new MonthCalendar(MinDate=Convert.ToDateTime("1 Jan,1999"),MaxDate=Convert.ToDateTime("1 Jan,8013"),Location=new System.Drawing.Point(30,10))  
  13. //change the title backcolor to crimson  
  14. calendar.TitleBackColor<-Color.Crimson  
  15. //applies the font to our calendar  
  16. calendar.Font<-myfont  
  17. //change the calendar backcolor to Bisque  
  18. calendar.BackColor<-Color.Bisque  
  19. //adds the calendar control to our form  
  20. calendarform.Controls.Add(calendar)  
  21. calendarform.Show()  
  22. //executes our application  
  23. Application.Run(calendarform)  
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: If you want a more in depth explanation on this controls, visit the MSDN website at msdn.microsoft.com or the Microsoft F# Development Center at http://msdn.microsoft.com/en-us/fsharp/default.aspx

Adding ToolTips(Visual F# Windows Forms Application)

Tooltips are typically used to display a descriptive text when the mouse pointer hovers a control. To create a tooltip, use the following syntax:
  1. let tooltipobjvaribale=new ToolTip()  
For example:
  1. let tip=new ToolTip()  
One of the essential methods of the ToolTip object is the SetToolTip method which allows user to connect the tooltip to a specified control. SetToolTip has the following syntax:
  1. tooltipobjvariable.SetToolTip(object variable of the control where you wanted to display the tooltip,”tooltiptext”)  
Example:
  1. tip.SetToolTip(addbutton,"Click here to add”)  

The following steps demonstrates a simple example in using ToolTips.

The following example demonstrate a simple application using WebBrowser control:

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.

4. Enter the following code after the line “// Learn more about F# at http://fsharp.net “:

  1. //uses the F# standard library  
  2. open System  
  3. //use the drawing classes   
  4. open System.Drawing  
  5. //specifies the location of the form class  
  6. open System.Windows.Forms   
  7. //make a form add set its caption to “Add Tooltip”  
  8. let myfont=new Font("Arial",8.0f,FontStyle.Bold, GraphicsUnit.Point)  
  9. let tipform=new Form(Text="Add Tooltip",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)  
  10. //create a label  
  11. let desclabel=new Label(Text="Hover your mouse on the button...",Width=400,AutoSize=false)  
  12. //make a button and assign an “Exit” to it  
  13. let exitbutton=new Button(Text="Exit",Location=new System.Drawing.Point(200,220))  
  14. //create a tooltip and set its Title to “Use ToolTip”  
  15. //enable the balloon form  
  16. //add a warning icon. Other icon values are warning and info  
  17. let tip=new ToolTip(ToolTipTitle="Use ToolTip",IsBalloon=true,ToolTipIcon=ToolTipIcon.Warning)  
  18. //add the controls to our form  
  19. tipform.Controls.Add(desclabel)  
  20. desclabel.Font<-myfont  
  21. desclabel.ForeColor<-Color.Red  
  22. tipform.Controls.Add(exitbutton)  
  23. //when the mouse hovers the exit button  
  24. exitbutton.MouseHover.Add(fun tipmsg->  
  25. //display our tip  
  26. tip.SetToolTip(exitbutton,"Click here to quit"))  
  27. //quits the form when the exit button is clicked  
  28. exitbutton.Click.Add(fun quit->tipform.Close())  
  29. tipform.Show()  
  30. //executes our application  
  31. Application.Run(tipform)  
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: