0% found this document useful (0 votes)
64 views3 pages

SelfTest-windows Form

The document provides instructions for creating a Windows form application to calculate the sum, difference, product, and quotient of two numbers. It describes adding text boxes to input the numbers and buttons for the operations (+,-,*,/). It then explains writing code in the button click events to convert the text box values to doubles, perform the calculations, and display the results in a message box.

Uploaded by

erza scarlet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views3 pages

SelfTest-windows Form

The document provides instructions for creating a Windows form application to calculate the sum, difference, product, and quotient of two numbers. It describes adding text boxes to input the numbers and buttons for the operations (+,-,*,/). It then explains writing code in the button click events to convert the text box values to doubles, perform the calculations, and display the results in a message box.

Uploaded by

erza scarlet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Problem: In this activity, you will create a windows form application that will compute the

sum, difference, product and quotient of the two numbers. Instruction:

1. Create windows application that can have single or multiple forms which are the
means of GUI representation.

2. Create a new project->Select Windows Form Application ->Give a proper project


name.

3. Then go to View ->ToolBox. Drag 2 TextBoxes from the ToolBox to the Design form
named Form1. In these 2 textboxes we will input 2 numbers for calculation. Give the
TextBoxes unique names: Select the TextBox ->Right Click -> Properties-> In Properties find
‘Name’ field and give a unique name to the Textbox. Suppose the 1st TextBox name is
txtNumber1 and the 2nd TextBox name is txtNumber2. See Expected Output Below.

4. Then we have to go to View ->ToolBox and add 4 Buttons for the operations (+,-,*, /).
Similarly give each Button a unique name in the ‘Name’ field. Here we have given the
Button’s name as follows: btnPlus, btnMinus, btnMultiplication and btnDivision. We also
have to show the symbols (+,-,*, /) on the Button. To do that, Select the 1st Button ->Right
Click ->Properties ->Find ‘Text’ field and write +. Do this for the other buttons as well. See
Expected Output Below.

5. Click the Buttons and perform the operations accordingly. So we have to write some
code for each Button’s ClickEvent. To do that, double click each button in the form and
then write the corresponding operations for the 2 numbers given input in the Textboxes
as shown below.

6. Here we are showing the output using a MessageBox.

Code:

using System.Windows.Forms;

namespace SimpleForm

public partial class Form1 : Form

public Form1()

InitializeComponent();

private void btnPlus_Click(object sender, EventArgs e)

{
double n1 = Convert.ToDouble(txtNumber1.Text);

double n2 = Convert.ToDouble(txtNumber2.Text);

double result = n1 + n2;

MessageBox.Show(n1 + "+" + n2 + " = " + result);

private void btnMinus_Click(object sender, EventArgs e)

double n1 = Convert.ToDouble(txtNumber1.Text);

double n2 = Convert.ToDouble(txtNumber2.Text);

double result = n1 - n2;

MessageBox.Show(n1 + "-" + n2 + " = " + result);

private void btnMultiplication_Click(object sender, EventArgs e)

double n1 = Convert.ToDouble(txtNumber1.Text);

double n2 = Convert.ToDouble(txtNumber2.Text);

double result = n1 * n2;

MessageBox.Show(n1 + "*" + n2 + " = " + result);

private void btnDivision_Click(object sender, EventArgs e)

double n1 = Convert.ToDouble(txtNumber1.Text);

double n2 = Convert.ToDouble(txtNumber2.Text);

double result = n1 / n2;

MessageBox.Show(n1 + "/" + n2 + " = " + result);

}
Expected Output:

Reference:

https://toaz.info/doc-viewer

You might also like