Picturebox Control(Visual F#)

Picturebox is a control used to display an image on your form. To create a picturebox, use the following syntax:
  1. let pictureboxobjvariable=new PictureBox()  
for instance:
  1. let picbox=new PictureBox()  
To specify the url of an image to display in the picturebox, use the Image property.

Syntax:
  1. pictureboxobjvariable.ImageLocation<-"url of an existent image"  
for instance:
  1. picbox.ImageLocation<-"C:\myimage.png"  
Just make sure that myimage.jpg exist on your computer. Follow the steps below for a simple example on using a picturebox. 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. //use the f# standard library  
  2. // Learn more about F# at http://fsharp.net  
  3.   
  4. open System  
  5. //use this to enable the intellisense. Very helpful in coding your application  
  6. open System.Drawing   
  7. //specify the location of the Form classes  
  8. open System.Windows.Forms   
  9. //create a form named imageform  
  10. let imageform=new Form(Text="Use PictureBox",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)  
  11. //creates a horizontal scrollbar  
  12. let hscroll=new HScrollBar(Location=new System.Drawing.Point(10, 230),Width=270)  
  13. //creates a tooltip  
  14. let tip=new ToolTip(IsBalloon=true,ToolTipIcon=ToolTipIcon.Info)  
  15. //creates a picturebox named picbox  
  16. //set the sizemode to autosize to adjust the size of the picturebox  
  17. //depending on the size of your image  
  18. //sets the picturebox borderstyle to fixed single  
  19. let picbox=new PictureBox(SizeMode=PictureBoxSizeMode.AutoSize,BorderStyle=BorderStyle.FixedSingle,Top=5)  
  20. picbox.ImageLocation<-("C:\suzzane.png")  
  21. //adds the picturebox on your form  
  22. imageform.Controls.Add(picbox)  
  23. imageform.Controls.Add(hscroll)  
  24. //adds the scrollbar to our form  
  25. //displays a tooltip when the mouse hovers the scrollbar  
  26. hscroll.MouseHover.Add(fun desc->tip.SetToolTip(hscroll,"Drag the scroll box to move the image"))  
  27. //change the horizontal position of the image when the scrollbox is moved  
  28. hscroll.Scroll.Add(fun move->picbox.Left<-Convert.ToInt32(hscroll.Value.ToString()))  
  29. imageform.Show()  
  30. Application.Run(imageform)  
  31. //executes your application  
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