In: Computer Science
Write a Windows Form application named SumFiveInts. Microsoft Visual C#: An Introduction to Object-Oriented Programming,7th Edition. Ch. 5, page 220. Take snip of program results.
Program:
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;
namespace SumFiveInts
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnCalculateSum_Click(object sender, EventArgs
e)
{
int no1, no2, no3, no4, no5, sum;
//storing values from textboxes into variables
no1 = Convert.ToInt32(txtNo1.Text);
no2 = Convert.ToInt32(txtNo2.Text);
no3 = Convert.ToInt32(txtNo3.Text);
no4 = Convert.ToInt32(txtNo4.Text);
no5 = Convert.ToInt32(txtNo5.Text);
//calculating sum
sum = no1 + no2 + no3 + no4 + no5;
//storing the result in textbox i.e. txtSum
txtSum.Text = sum.ToString();
}
private void Form1_Load(object sender, EventArgs e)
{
//so the result can't be edit manually
txtSum.Enabled = false;
}
}
}
Output:
Note:
Button: btnCalculateSum
TextBox1: txtNo1
TextBox2: txtNo2
TextBox3: txtNo3
TextBox4: txtNo4
TextBox5: txtNo5
TextBox6: txtSum
Form : Form1