Determine the Area of Annulus in Windows Form Using F#

Introduction

This article explains the "Annulus" and how to calculate the area of an Annulus in a Windows Forms application. An Annulus is the part of a large circle remaining when a small circle with the same center is cut out. The area is simply the area of a large circle minus the area of the small circle.

Annulus

An "Annulus" is a flat shape like a ring. The area of the Annulus is the area of the ring-shaped space between the two circles that define it; the region lying between two concentric circles. The area of the Annulus is determined by the two circles of a and b (with a>b). Its edges have the two circles that have the same center. The area of the circle whose diameter is tangent to the inner circle and has endpoints at the outer circle is equal to the area of the Annulus.

The area of the Annulus = the area of the large circle - the area of the small circle.

Annulus

Now  I will show you how to find the area of an Annulus in  a Windows Forms application. Use the following procedure to create the sample.

Step 1:

Open Visual Studio then select "Create New Project" --> "F# Console Application".

CreateApplication

Step 2:

Now go to the right side of the Solution Explorer. Right-click on "References" and select "Add references".

SelectReferences

 


AddReferences

Step 3:

After selecting "Add References", in the framework template you need to select "System.Windows.Forms" and "System.Drawing" while holding down the Ctrl key and click on "Ok."

ImportNamespaces

Step 4:

Use the following code to determine the area of the Annulus in the F# editor.

open System  

open System.Windows.Forms  

open System.ComponentModel  

open System.Drawing  

let calcform=new Form(Text="Find Area of Annulus")  

calcform.BackColor<-Color.DarkGray

let lrgcirclbl=new Label(Top=20,Left=0,Width=120)

lrgcirclbl.Text<-"Area of a large circle:"  

let largecircletxt=new TextBox(Top=20,Left=130)  

let smllbl=new Label(Top=60,Left=0,Width=120)  

smllbl.Text<-"Area of a small circle"

let smallcircletxt=new TextBox(Top=60,Left=130)  

let annuluslbl=new Label(Top=100,Left=20,Width=120)  

annuluslbl.Text<-"Area of an annulus:"

let resultlbl=new Label(Top=100,Left=140,BorderStyle=BorderStyle.FixedSingle)  

let computebutton=new Button(Top=140,Left=70,Width=80)

computebutton.Text<-"Calculate" 

computebutton.BackColor<-Color.Ivory 

let exitbutton=new Button(Top=140,Left=160,Width=60)

exitbutton.Text<-"Exit"  

exitbutton.BackColor<-Color.Ivory

calcform.Controls.Add(lrgcirclbl)  

calcform.Controls.Add(largecircletxt)  

calcform.Controls.Add(smllbl)  

calcform.Controls.Add(smallcircletxt)  

calcform.Controls.Add(annuluslbl)  

calcform.Controls.Add(resultlbl)  

calcform.Controls.Add(computebutton)  

calcform.Controls.Add(exitbutton)  

computebutton.Click.Add(fun find ->  

let areaoflargecircle=Convert.ToDouble(largecircletxt.Text)  

let areaofsmallcircle=Convert.ToDouble(smallcircletxt.Text)  

let areaofannulus=areaoflargecircle-areaofsmallcircle   

resultlbl.Text<-Convert.ToString(areaofannulus))             

exitbutton.Click.Add(fun exit -> calcform.Close())    

Application.Run(calcform)  

Step 5 :

Debug the application by pressing F5 to execute the Windows Forms application. After debugging the application the output will be as in the following figure:

AferDebug

Step 6 :

Enter the value of the Large Circle as in the following figure:

ValueOfLargeCircle

Step 7 :

Enter the value of the Small Circle as in the following figure:

ValueOfSmallCircle

Step 8 :

Click on the Calculate button and you will get the area of the Annulus as in the following figure:

AreaOfAnnulus

Summary

This article explained what an Annulus is.

Up Next
    Ebook Download
    View all
    Learn
    View all