How to make a simple Age calculator in c#

April 23, 2013

How to make a simple Age calculator in c#


age calculator  waqeeh ul hasan



age calculator  waqeeh ul hasan



age calculator  waqeeh ul hasan



age calculator  waqeeh ul hasan






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 Age_Calculator
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            DateTime dateOfBirth;
            DateTime.TryParse(maskedTextBox1.Text, out dateOfBirth);
            DateTime currentDate = DateTime.Now;
            TimeSpan difference = currentDate.Subtract(dateOfBirth);
            DateTime age = DateTime.MinValue + difference;
            int ageInYears = age.Year - 1;
            int ageInMonths = age.Month - 1;
            int ageInDays = age.Day - 1;
            textBox1.Text = (ageInYears).ToString();
            textBox2.Text = (ageInMonths).ToString();
            textBox3.Text = (ageInDays).ToString();
        }

        private void button1_MouseHover(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(this.button1, "Enter to Calculate Your Age");
        }

        private void maskedTextBox1_MouseHover(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(this.maskedTextBox1, "Enter your Birth Date");
        }

        private void button2_Click(object sender, EventArgs e)
        {
                Application.Exit();
        }

        private void button2_MouseHover(object sender, EventArgs e)
        {
            toolTip1.SetToolTip(this.button2, "Exit");
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult result;
            result = MessageBox.Show("Do you realy want to close", "Confirmation", MessageBoxButtons.YesNo);
            if (result == DialogResult.No)
            {
                e.Cancel = true;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}



You Might Also Like

0 comments

Popular Posts

Like us on Facebook

Flickr Images