Monday, September 26, 2016

Area of Rectangle in C#

Here is a another simple program that I wrote in C# to ask the user to give the length and breath of the rectangle and the our program will compute for its area. I am using Visual Studio 2010 Ultimate Edition in this program.

Add me at Facebook my address is jakerpomperada@gmail.com and jakerpomperada@yahoo.com. 


My mobile number here in the Philippines is 09173084360.




Sample Program Output


Program Listing

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int length= 0, breadth=0,solve_area=0;

            if (!int.TryParse(textBox1.Text, out length))
            {
                MessageBox.Show("I need just a number in the textbox.");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox1.Focus();
            }
            else  if (!int.TryParse(textBox2.Text, out breadth))
            {
                MessageBox.Show("I need just a number in the textbox.");
                textBox1.Text = "";
                textBox2.Text = "";
                textBox1.Focus();
            }


            else
            {
                length = Convert.ToInt32(textBox1.Text);
                breadth = Convert.ToInt32(textBox2.Text);

                solve_area = (length * breadth);
                label5.Text = "The Area of the Rectangle is " + solve_area + ".";
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Text = "";
            textBox2.Text = "";
            label5.Text = " ";
            textBox1.Focus();
        }
    }
}







No comments:

Post a Comment