0% found this document useful (0 votes)
8 views2 pages

Homework 1

This document provides step-by-step instructions for creating a Windows Forms application in Visual Studio 2008 to sum two floating-point numbers. It details the process of setting up the project, adding controls like labels and text boxes, and writing the necessary code to perform the calculation. Finally, it includes instructions for saving and running the application.

Uploaded by

Ahmed Al-nasheri
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

Homework 1

This document provides step-by-step instructions for creating a Windows Forms application in Visual Studio 2008 to sum two floating-point numbers. It details the process of setting up the project, adding controls like labels and text boxes, and writing the necessary code to perform the calculation. Finally, it includes instructions for saving and running the application.

Uploaded by

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

Windows Application to Sum Two Numbers

EVERYTHING IN BOLD MUST BE TYPED IN EXACTLY AS IT APPEARS!!!

1. Create the new project.


a. Open Visual Studio 2008 (Lab Applications/Software Development
/Microsoft Visual Studio 2008/Microsoft Visual Studio 2008). Select File
> New > Project IMPORTANT: Visual Basic is selected by default Under
project type, select Visual C# and then on the right select Windows Forms
Application.
b. Name the project SumNumbers and select a directory in which to save
the project, preferably your personal USB drive.
c. Click OK. Visual Studio will load the new solution and a form labeled
Form1 will appear.
2. Rename the source code file.
a. Double-click the Solution Explorer in the toolbar or select View >
Solution Explorer.
b. Right-click on Form1.cs to rename as SumNumbers.cs
c. Select “Yes” on the dialog box regarding the references.
3. Set the form’s name and title bar.
a. Click once on the form.
b. Click the Properties icon in the toolbar or select the View menu’s
Properties Window command. The Properties Window shows information
about the currently selected object.
c. Click in the box to the right of the Text property’s box. Type
Sum Numbers
d. Resize the form to the desired size by clicking and dragging the form’s
sizing handles.
4. Add the first label control to the form.
a. Click the Toolbox icon in the toolbar or select View > Toolbox. You can
click on the pin icon to lock the toolbox in place.
b. Double-click the label control in the Toolbox.
c. Position the label on the form.
d. In the Properties Window, change the Text property of the label to First
Floating-Point Value:
e. In the Properties Window, change the Name of the label to
firstNumberLabel
5. Add the second label control to the form.
a. Double-click the label control in the Toolbox.
b. Position the label on the form.
c. Change the Text property to Second Floating-Point Value:
d. Change the Name to secondNumberLabel
6. Add a TextBox to the form.
a. Double-click the TextBox control in the ToolBox.
b. Position the TextBox to the right of the first label.
c. Change the Name of the TextBox to firstNumberTextBox
7. Add the second TextBox to the form.
a. Drag a TextBox control from the ToolBox, positioning the TextBox to the
right of the second label.
b. Change the Name of the TextBox to secondNumberTextBox
8. Add a label to the form to display the result.
a. Drag a label control from the ToolBox to the form, positioning it below
the TextBoxes.
b. Go to the Text property. Delete the text label1. Leave this as a blank
label. It will be used to hold the sum of the two numbers when the
program runs. (It will also not be visible on the form due to the fact that is
was made blank.)
c. Change the Name of the label to sumLabel
9. Add a button control to the form.
a. Drag a Button control from the ToolBox, position it below the two label
controls.
b. Change the Text property of the Button to Calculate Sum
c. Change the Name of the Button to calculateButton
d. Repostition and resize button, if needed.
e. Close or minimize the Toolbox.
f. Double-click the calculateButton control. This will add a
calculateButton_Click method to the SumNumbers class.
g. Type in the following lines of code EXACTLY AS THEY APPEAR.

//get input values and convert strings to doubles


double number1 = Double.Parse (firstNumberTextBox.Text);
double number2 = Double.Parse (secondNumberTextBox.Text);

//sum the two numbers


double sum = number1 + number2;

//display maximum value


sumLabel.Text = "Sum is: " + sum;

10. Save the project and the C# file.


a. Select File > Save All
11. Run the project.
a. Click on Build > Build Solution.
b. Click the Start button (the green triangle) or click on Debug > Start.
c. Put some values in the text boxes, click the Calculate button.
12. Terminating execution.
a. Click the running application’s Close button or click the End button in the
toolbar.

You might also like