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:
  1. Objectvariable.Cursor<-Cursors.CursorStyle  
For example:
  1. 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 “:
  1. // Learn more about F# at http://fsharp.net  
  2. //specify the namespace memory location  
  3. //of the classes that will be needed in our application  
  4. open System  
  5. open System.Drawing  
  6. open System.Windows.Forms  
  7. //create our controls  
  8. let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)  
  9. 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)  
  10. let llabel1=new Label(Text="Hand Cursor",AutoSize=true,Location=new System.Drawing.Point(20, 80))  
  11. let llabel2=new Label(Text="AppStarting Cursor",AutoSize=true,Location=new System.Drawing.Point(120,80))  
  12. //add the controls into our form  
  13. myform.Controls.Add(llabel1)  
  14. myform.Controls.Add(llabel2)  
  15. //add a mousehover and mouseleave events to our controls  
  16. //when the mouse hovers our labels, its cursor style,forecolor, and font size will change  
  17. //when the mouse leaves our control, the cursor style, label forecolor, and font size will  
  18. //return back to default  
  19. llabel1.MouseHover.Add(fun disphandcursor->  
  20.                   llabel1.ForeColor<-Color.Red  
  21.                   llabel1.Cursor<-Cursors.Hand  
  22.                   let ffont=new System.Drawing.Font("Microsoft Sans Serif",12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)  
  23.                   llabel1.Font<-ffont)  
  24. llabel1.MouseLeave.Add(fun changefontsize->  
  25.                   llabel1.ForeColor<-Color.Empty  
  26.                   let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)  
  27.                   llabel1.Font<-ffont)  
  28. llabel2.MouseHover.Add(fun dispappcursor->  
  29.                   llabel2.ForeColor<-Color.Red  
  30.                   llabel2.Cursor<-Cursors.AppStarting  
  31.                   let ffont=new System.Drawing.Font("Microsoft Sans Serif",12.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)  
  32.                   llabel2.Font<-ffont)  
  33. llabel2.MouseLeave.Add(fun retainsfontsize->  
  34.                   llabel2.ForeColor<-Color.Empty  
  35.                   let ffont=new System.Drawing.Font("Microsoft Sans Serif",9.0F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point)  
  36.                   llabel2.Font<-ffont)                
  37. myform.Show()  
  38. //executes our application  
  39. Application.Run(myform)  
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: