Question

In: Computer Science

Create a new “Area” project. Create a new Visual Studio Project and call it “Area”. This...

  1. Create a new “Area” project.
    1. Create a new Visual Studio Project and call it “Area”.
    2. This project will be used to calculate the area of certain figures, like circles, squares and rectangles.
    3. So add a title to the Form. The Form Title should say “Area”. Also add 3 labels, 3 Buttons, 3 Textboxes and 3 RadioButtons. The 3 Buttons should be near the bottom of the Form and say “Calc Area”, “Clear” and “Exit”. Make sure to give all your components names that make sense, like we did in the “GoTeam” project. The Labels and Textboxes should be near the top towards the right side. The labels should say “Radius”, “Width” and “Area” and the 3 Textboxes should be empty. And the 3 RadioButtons should be in the middle near the left side. They should read “Circle”, “Square” and “Rectangle”.
    4. Add all these components and run this project. Use the Properties window to change any colors or Fonts that you would like.

Assign 2: Add to the “Area” project from Lab #1.  

  1. When the user selects the “Circle” radio button….make sure the top Label says “Radius:” and only one textbox is visible.
  2. Then when the user clicks on the “Calculate” button…..calculate the area of a circle and display it in the “Area” textbox.   
  3. When the user selects the “Square” radio button…. make sure the top Label says “Side:” and only one textbox is visible.
  4. Then when the user clicks on the “Calculate” button…..calculate the area of a square and display it in the “Area” textbox.
  5. When the user selects the “Rectangle” radio button…. make sure the top Label says “Height:” and the bottom Label say “Width:”. and only one textbox is visible.
  6. Then when the user clicks on the “Calculate” button…..calculate the area of a rectangle and display it in the “Area” textbox.
  7. Add an “Exit” button to this project. Make the exit button work.

Add a “Clear” button to this project. Also make the Clear button work, clear should clear all textbaoxes

Solutions

Expert Solution

Dear Student ,

As per the requirement submitted above , kindly find the below solution.

Here a new Windows Forms Application in C# is created using Visual Studio 2017 with name "Area".This application contains a form with name "Form1.cs".Below are the files associated with form1.

1.Form1.cs[Design]

2.Form1.Designer.cs

namespace Area
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.lblRadius = new System.Windows.Forms.Label();
this.btnCalcArea = new System.Windows.Forms.Button();
this.rbtCircle = new System.Windows.Forms.RadioButton();
this.btnClear = new System.Windows.Forms.Button();
this.btnExit = new System.Windows.Forms.Button();
this.txtRadius = new System.Windows.Forms.TextBox();
this.txtWidth = new System.Windows.Forms.TextBox();
this.lblWidth = new System.Windows.Forms.Label();
this.txtArea = new System.Windows.Forms.TextBox();
this.lblArea = new System.Windows.Forms.Label();
this.rbtSquare = new System.Windows.Forms.RadioButton();
this.rbtRectangle = new System.Windows.Forms.RadioButton();
this.SuspendLayout();
//
// lblRadius
//
this.lblRadius.AutoSize = true;
this.lblRadius.Location = new System.Drawing.Point(12, 18);
this.lblRadius.Name = "lblRadius";
this.lblRadius.Size = new System.Drawing.Size(40, 13);
this.lblRadius.TabIndex = 0;
this.lblRadius.Text = "Radius";
//
// btnCalcArea
//
this.btnCalcArea.Location = new System.Drawing.Point(27, 120);
this.btnCalcArea.Name = "btnCalcArea";
this.btnCalcArea.Size = new System.Drawing.Size(75, 23);
this.btnCalcArea.TabIndex = 1;
this.btnCalcArea.Text = "&Calc Area";
this.btnCalcArea.UseVisualStyleBackColor = true;
this.btnCalcArea.Click += new System.EventHandler(this.btnCalcArea_Click);
//
// rbtCircle
//
this.rbtCircle.AutoSize = true;
this.rbtCircle.Location = new System.Drawing.Point(218, 18);
this.rbtCircle.Name = "rbtCircle";
this.rbtCircle.Size = new System.Drawing.Size(51, 17);
this.rbtCircle.TabIndex = 2;
this.rbtCircle.TabStop = true;
this.rbtCircle.Text = "Circle";
this.rbtCircle.UseVisualStyleBackColor = true;
this.rbtCircle.CheckedChanged += new System.EventHandler(this.rbtCircle_CheckedChanged);
//
// btnClear
//
this.btnClear.Location = new System.Drawing.Point(120, 120);
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(75, 23);
this.btnClear.TabIndex = 3;
this.btnClear.Text = "C&lear";
this.btnClear.UseVisualStyleBackColor = true;
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(217, 120);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(75, 23);
this.btnExit.TabIndex = 4;
this.btnExit.Text = "E&xit";
this.btnExit.UseVisualStyleBackColor = true;
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// txtRadius
//
this.txtRadius.Location = new System.Drawing.Point(66, 15);
this.txtRadius.Name = "txtRadius";
this.txtRadius.Size = new System.Drawing.Size(100, 20);
this.txtRadius.TabIndex = 5;
//
// txtWidth
//
this.txtWidth.Location = new System.Drawing.Point(66, 47);
this.txtWidth.Name = "txtWidth";
this.txtWidth.Size = new System.Drawing.Size(100, 20);
this.txtWidth.TabIndex = 7;
//
// lblWidth
//
this.lblWidth.AutoSize = true;
this.lblWidth.Location = new System.Drawing.Point(12, 50);
this.lblWidth.Name = "lblWidth";
this.lblWidth.Size = new System.Drawing.Size(35, 13);
this.lblWidth.TabIndex = 6;
this.lblWidth.Text = "Width";
//
// txtArea
//
this.txtArea.Location = new System.Drawing.Point(66, 77);
this.txtArea.Name = "txtArea";
this.txtArea.Size = new System.Drawing.Size(100, 20);
this.txtArea.TabIndex = 9;
//
// lblArea
//
this.lblArea.AutoSize = true;
this.lblArea.Location = new System.Drawing.Point(12, 80);
this.lblArea.Name = "lblArea";
this.lblArea.Size = new System.Drawing.Size(29, 13);
this.lblArea.TabIndex = 8;
this.lblArea.Text = "Area";
//
// rbtSquare
//
this.rbtSquare.AutoSize = true;
this.rbtSquare.Location = new System.Drawing.Point(218, 50);
this.rbtSquare.Name = "rbtSquare";
this.rbtSquare.Size = new System.Drawing.Size(59, 17);
this.rbtSquare.TabIndex = 10;
this.rbtSquare.TabStop = true;
this.rbtSquare.Text = "Square";
this.rbtSquare.UseVisualStyleBackColor = true;
this.rbtSquare.CheckedChanged += new System.EventHandler(this.rbtSquare_CheckedChanged);
//
// rbtRectangle
//
this.rbtRectangle.AutoSize = true;
this.rbtRectangle.Location = new System.Drawing.Point(218, 80);
this.rbtRectangle.Name = "rbtRectangle";
this.rbtRectangle.Size = new System.Drawing.Size(74, 17);
this.rbtRectangle.TabIndex = 11;
this.rbtRectangle.TabStop = true;
this.rbtRectangle.Text = "Rectangle";
this.rbtRectangle.UseVisualStyleBackColor = true;
this.rbtRectangle.CheckedChanged += new System.EventHandler(this.rbtRectangle_CheckedChanged);
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(312, 171);
this.Controls.Add(this.rbtRectangle);
this.Controls.Add(this.rbtSquare);
this.Controls.Add(this.txtArea);
this.Controls.Add(this.lblArea);
this.Controls.Add(this.txtWidth);
this.Controls.Add(this.lblWidth);
this.Controls.Add(this.txtRadius);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.btnClear);
this.Controls.Add(this.rbtCircle);
this.Controls.Add(this.btnCalcArea);
this.Controls.Add(this.lblRadius);
this.Name = "Form1";
this.Text = "Area";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

#endregion

private System.Windows.Forms.Label lblRadius;
private System.Windows.Forms.Button btnCalcArea;
private System.Windows.Forms.RadioButton rbtCircle;
private System.Windows.Forms.Button btnClear;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.TextBox txtRadius;
private System.Windows.Forms.TextBox txtWidth;
private System.Windows.Forms.Label lblWidth;
private System.Windows.Forms.TextBox txtArea;
private System.Windows.Forms.Label lblArea;
private System.Windows.Forms.RadioButton rbtSquare;
private System.Windows.Forms.RadioButton rbtRectangle;
}
}

3.Form1.cs

//namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//application namespace
namespace Area
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Form load event
private void Form1_Load(object sender, EventArgs e)
{
//hide all labels and textboxes
lblRadius.Visible = false;
lblWidth.Visible = false;
lblArea.Visible = false;
txtArea.Visible = false;
txtRadius.Visible = false;
txtWidth.Visible = false;

}
//when circle radio button is selected
private void rbtCircle_CheckedChanged(object sender, EventArgs e)
{
//make label and textbox visible
lblRadius.Visible = true;
txtRadius.Visible = true;
txtWidth.Visible = false;
lblWidth.Visible = false;
lblArea.Visible = false;
txtArea.Visible = false;
}
//when square radio button is selected
private void rbtSquare_CheckedChanged(object sender, EventArgs e)
{
//make label and textbox visible
lblRadius.Visible = true;
lblRadius.Text = "Side";
txtRadius.Visible = true;
txtWidth.Visible = false;
lblWidth.Visible = false;

}
//when rectangle radio button is selected
private void rbtRectangle_CheckedChanged(object sender, EventArgs e)
{
//make label and textbox visible
lblRadius.Visible = true;
lblRadius.Text = "Height";
txtRadius.Visible = true;
txtWidth.Visible = true;
lblWidth.Visible = true;
lblArea.Visible = false;
txtArea.Visible = false;
}
//calculate button click
private void btnCalcArea_Click(object sender, EventArgs e)
{
//checking which radio button is selected
if(rbtCircle.Checked==true)
{
//if circle radio button is selected then
//taking radius enered by user
double radius = double.Parse(txtRadius.Text);
//calculate and display area of circle
txtArea.Text = (Math.PI * radius * radius).ToString("0.00");
txtArea.Visible = true;
lblArea.Visible = true;
}
//checking which radio is selected
else if (rbtSquare.Checked == true)
{
//if Square radio button is selected then
//taking side enered by user
double side = double.Parse(txtRadius.Text);
//calculate and display area of square
txtArea.Text = (side*side).ToString("0.00");
txtArea.Visible = true;
lblArea.Visible = true;
}
//checking which radio is selected
else if (rbtRectangle.Checked == true)
{
//if rectangle radio button is selected then
//taking height and width enered by user
double height = double.Parse(txtRadius.Text);
//taking width entered by user
double width = double.Parse(txtWidth.Text);
//calculate and display area of rectangle
txtArea.Text = (height * width).ToString("0.00");
txtArea.Visible = true;
lblArea.Visible = true;
}
}
//Clear button click
private void btnClear_Click(object sender, EventArgs e)
{
//when clear button clicked ,clear all textboxes
txtArea.Text = "";
txtRadius.Text = "";
txtWidth.Text = "";
}
//Exit button click
private void btnExit_Click(object sender, EventArgs e)
{
//When exit button clicked , close the form
this.Close();
}
}
}

======================================================

Output : Run application using F5 and will get the screen as shown below

Screen 1 :

Screen 2 :Screen showing area of circle

Screen 3 :Screen showing area of square

Screen 4 :Screen showing area of rectangle

NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.


Related Solutions

Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in...
Create a new Visual Studio console project named assignment042, and translate the algorithm you developed in Assignment 04.1 to C++ code inside the main() function. Your program should prompt for a single 9-digit routing number without spaces between digits as follows: Enter a 9-digit routing number without any spaces: The program should output one of: Routing number is valid Routing number is invalid A C++ loop and integer array could be used to extract the routing number's 9 digits. However...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of...
Create a C# .NET Core Console project in Visual Studio. (This is the same kind of project we have been doing all semester.) Do all of the following in the Program class. You do not need to add any other classes to this project. 2. If it exists, remove the Console.WriteLine(“Hello World!”); line that Visual Studio created in the Program class. 3. At the very top of the Program.cs page you should see using System; On the empty line below...
Create a C++ project in visual studio. You can use the C++ project that I uploaded...
Create a C++ project in visual studio. You can use the C++ project that I uploaded to complete this project. 1. Write a function that will accept two integer matrices A and B by reference parameters, and two integers i and j as a value parameter. The function will return an integer m, which is the (i,j)-th coefficient of matrix denoted by A*B (multiplication of A and B). For example, if M = A*B, the function will return m, which...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project...
1. Start a new Visual Studio project and name it GradeAppa. Make sure your project is a web projectb. Make sure it is using C#2. Add a new folder and name it Grades_Logic3. Inside this new folder create a new web form called “Grades”4. Add a label to hold text “Enter Grade”5. Add a text field in front of the label to receive the grade6. Add another label in a new line to display the text “Participation”7. Place a drop-down...
Create a Visual Studio console project (c++) containing a main() program that declares a const int...
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name...
Create a Visual Studio console project named exercise101. The main() function should prompt for the name of a text file located in the same directory as exercise101.cpp, and search for a word in the text file as follows: Enter text file name: Enter search word: The program should print the number of occurrences of the word in the file: occurrences of were found in If the file could not be opened then display: File not found Use Stream file I/O...
Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function...
Create a Visual Studio console project named exercise093. In the exercise093.cpp file first define a function void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all...
Create a Visual Studio console project using c++ void lowerToUpper(std::string & sentence) that iterates over all characters in the sentence argument. Any lowercase letter should be converted to uppercase. This can be done by including <cctype> and testing each character in sentence with the islower() function. If islower(sentence[i]) returns true then sentence[i] should be replaced with toupper(sentence[i]). The main() function should assign "Hello how are you doing?" to sentence, call lowerToUpper(sentence), and use an if statement to check the new...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3...
Create an ASP.Net Website using Visual Studio with C#: Create a simple calculator that has 3 text boxes: 2 of them to enter numbers, the 3rd one displays the results Create 4 buttons to add, subtract, multiply, and divide Prevent the user from entering text in the number fields Display a message indicating “cannot divide by” when the user click “/” and there is a zero the in the second box Create two additional buttons: - One to store data...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT