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:
  1. Let propertygridobjvariable=new PropertyGrid()  
For example:
  1. 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:
  1. Propertygridvariable.SelectedObject<-Objvariable  
For example:
  1. 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 “:
  1. // Learn more about F# at http://fsharp.net  
  2. //use the F# library  
  3. open System  
  4. //use the drawing class. Enables intellisense  
  5. open System.Drawing  
  6. //use the form class  
  7. open System.Windows.Forms  
  8. //creates a new form  
  9. let myform=new Form(Text="Use Process Grid",StartPosition=FormStartPosition.CenterScreen,AutoScaleMode=AutoScaleMode.Font)  
  10. //creates a textbox  
  11. let txtbox=new TextBox(Text="Textbox", Location=new System.Drawing.Point(5, 240))  
  12. //creates a label  
  13. let lbl=new Label(Text="Label", Location=new System.Drawing.Point(120, 240),AutoSize=true,BorderStyle=BorderStyle.FixedSingle)  
  14. //make a button from the button class  
  15. let button=new Button(Text="Button", Location=new System.Drawing.Point(200, 240))  
  16. //make a property grid control  
  17. let props=new PropertyGrid(Size=new System.Drawing.Size(180, 220),Left=50)  
  18. //adds a descriptive label  
  19. let desc=new Label(Text="Click the control below to view its properties...",AutoSize=true,Top=220)  
  20. //add the controls to our form  
  21. myform.Controls.Add(txtbox)  
  22. myform.Controls.Add(lbl)  
  23. myform.Controls.Add(button)  
  24. myform.Controls.Add(props)  
  25. myform.Controls.Add(desc)  
  26. //when the txtbox is clicked,display its properties in the property grid  
  27. txtbox.Click.Add(fun txtprops->props.SelectedObject<-txtbox)  
  28. //when the label is clicked,display its properties in the property grid  
  29. lbl.Click.Add(fun txtprops->props.SelectedObject<-lbl)  
  30. //when the button is clicked,display its properties in the property grid  
  31. button.Click.Add(fun txtprops->props.SelectedObject<-button)  
  32. myform.Show()  
  33. //executes our application  
  34. Application.Run(myform)  
5. Click the run icon to execute your application. You should now see an output similar to the following screen shot: