Drawing Triangles and Circles

To draw a triangle, use the DrawLine or DrawPolygon method. Here’s an example that uses DrawPolygon method:
  1. // Learn more about F# at http://fsharp.net  
  2. // Learn more about F# at http://fsharp.net  
  3. //specifies the memory location of the class files  
  4. //that will be needed in our application  
  5. open System.Collections.Generic  
  6. open System  
  7. open System.Windows.Forms  
  8. open System.ComponentModel  
  9. open System.Drawing  
  10. let graphicform = new Form(Text="Draw Triangle",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 250),StartPosition=FormStartPosition.CenterScreen)  
  11. //creates our control  
  12. let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))  
  13. graphicform.Paint.Add(fun draw->  
  14. let array=[|new Point(0,150);new Point(150,10);new Point(300,150)|]  
  15. let pen=new Pen(Color.Blue,Width=12.0f)  
  16. draw.Graphics.DrawPolygon(pen,array))  
  17. graphicform.Controls.Add(exitbutton)  
  18. //executes our application  
  19. Application.Run(graphicform)  
To draw a filled triangle, use the FillPolygon method:
  1. // Learn more about F# at http://fsharp.net  
  2. // Learn more about F# at http://fsharp.net  
  3. //specifies the memory location of the class files  
  4. //that will be needed in our application  
  5. open System.Collections.Generic  
  6. open System  
  7. open System.Windows.Forms  
  8. open System.ComponentModel  
  9. open System.Drawing  
  10. let graphicform = new Form(Text="Draw Triangle",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 250),StartPosition=FormStartPosition.CenterScreen)  
  11. //creates our control  
  12. let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))  
  13. graphicform.Paint.Add(fun draw->  
  14. let array=[|new Point(0,150);new Point(150,10);new Point(300,150)|]  
  15. let brush=new SolidBrush(Color.Blue)  
  16. draw.Graphics.FillPolygon(brush,array))  
  17. graphicform.Controls.Add(exitbutton)  
  18. //executes our application  
  19. Application.Run(graphicform)  
To draw a circle, use the DrawEllipse method:
  1. // Learn more about F# at http://fsharp.net  
  2. // Learn more about F# at http://fsharp.net  
  3. //specifies the memory location of the class files  
  4. //that will be needed in our application  
  5. open System.Collections.Generic  
  6. open System  
  7. open System.Windows.Forms  
  8. open System.ComponentModel  
  9. open System.Drawing  
  10. let graphicform = new Form(Text="Draw Circle",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 250),StartPosition=FormStartPosition.CenterScreen)  
  11. //creates our control  
  12. let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))  
  13. graphicform.Paint.Add(fun draw->  
  14.   
  15. let pen=new Pen(Color.Blue,Width=12.0f)  
  16. draw.Graphics.DrawEllipse(pen,0.0f,0.0f,100.0f,100.0f))  
  17.   
  18. graphicform.Controls.Add(exitbutton)  
  19. //executes our application  
  20. Application.Run(graphicform)  
To draw a solid circle, use the FillEllipse method:
  1. // Learn more about F# at http://fsharp.net  
  2. // Learn more about F# at http://fsharp.net  
  3. //specifies the memory location of the class files  
  4. //that will be needed in our application  
  5. open System.Collections.Generic  
  6. open System  
  7. open System.Windows.Forms  
  8. open System.ComponentModel  
  9. open System.Drawing  
  10. let graphicform = new Form(Text="Draw Circle",AutoScaleDimensions=new System.Drawing.SizeF(60.0F, 13.0F),ClientSize=new System.Drawing.Size(300, 250),StartPosition=FormStartPosition.CenterScreen)  
  11. //creates our control  
  12. let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))  
  13. graphicform.Paint.Add(fun draw->  
  14.   
  15. let brush=new SolidBrush(Color.Blue)  
  16. draw.Graphics.FillEllipse(brush,0.0f,0.0f,100.0f,100.0f))  
  17.   
  18. graphicform.Controls.Add(exitbutton)  
  19. //executes our application  
  20. Application.Run(graphicform)