Drawing Triangles and Circles

To draw a triangle, use the DrawLine or DrawPolygon method. Here’s an example that uses DrawPolygon method:
// Learn more about F# at http://fsharp.net
// Learn more about F# at http://fsharp.net
//specifies the memory location of the class files
//that will be needed in our application
open System.Collections.Generic
open System
open System.Windows.Forms
open System.ComponentModel
open System.Drawing
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)
//creates our control
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))
graphicform.Paint.Add(fun draw->
let array=[|new Point(0,150);new Point(150,10);new Point(300,150)|]
let pen=new Pen(Color.Blue,Width=12.0f)
draw.Graphics.DrawPolygon(pen,array))
graphicform.Controls.Add(exitbutton)
//executes our application
Application.Run(graphicform)
To draw a filled triangle, use the FillPolygon method:
// Learn more about F# at http://fsharp.net
// Learn more about F# at http://fsharp.net
//specifies the memory location of the class files
//that will be needed in our application
open System.Collections.Generic
open System
open System.Windows.Forms
open System.ComponentModel
open System.Drawing
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)
//creates our control
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))
graphicform.Paint.Add(fun draw->
let array=[|new Point(0,150);new Point(150,10);new Point(300,150)|]
let brush=new SolidBrush(Color.Blue)
draw.Graphics.FillPolygon(brush,array))
graphicform.Controls.Add(exitbutton)
//executes our application
Application.Run(graphicform)
To draw a circle, use the DrawEllipse method:
// Learn more about F# at http://fsharp.net
// Learn more about F# at http://fsharp.net
//specifies the memory location of the class files
//that will be needed in our application
open System.Collections.Generic
open System
open System.Windows.Forms
open System.ComponentModel
open System.Drawing
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)
//creates our control
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))
graphicform.Paint.Add(fun draw->

let pen=new Pen(Color.Blue,Width=12.0f)
draw.Graphics.DrawEllipse(pen,0.0f,0.0f,100.0f,100.0f))

graphicform.Controls.Add(exitbutton)
//executes our application
Application.Run(graphicform)
To draw a solid circle, use the FillEllipse method:
// Learn more about F# at http://fsharp.net
// Learn more about F# at http://fsharp.net
//specifies the memory location of the class files
//that will be needed in our application
open System.Collections.Generic
open System
open System.Windows.Forms
open System.ComponentModel
open System.Drawing
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)
//creates our control
let exitbutton=new Button(Text="Exit", Location=new System.Drawing.Point(190, 200))
graphicform.Paint.Add(fun draw->

let brush=new SolidBrush(Color.Blue)
draw.Graphics.FillEllipse(brush,0.0f,0.0f,100.0f,100.0f))

graphicform.Controls.Add(exitbutton)
//executes our application
Application.Run(graphicform)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.