1/11/2012

percentage of change in C# windows Form Application

 

Percentage Of Change Calculator C# Windows Form
Percentage Of Change Calculator in C# Windows Form



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.Windows.Forms;

namespace PercentageOfChangeCalculator
{
    public partial class MainForm : Form
    {
        double initial, final;
        public frmPercentageOfChangeCalculator()
        {
            InitializeComponent();
        }

        private void clearButton_Click(object sender, EventArgs e)
        {
            initialValueTextBox.Clear();
            finalValueTextBox.Clear();
            initialValueTextBox.Focus();
            resultLabel.Text = null;
        }

        private void calculateButton_Click(object sender, EventArgs e)
        {
            if (double.TryParse(initialValueTextBox.Text, out initial) && double.TryParse(finalValueTextBox.Text, out final))
            {
                double percentage = ((final - initial) / initial) * 100;
                resultLabel.Text = $"Percentage of change: {percentage}%";
            }
            else
            {
                MessageBox.Show("Please enter valid numeric values for initial and final values.");
            }
        }
    }
}

No comments:

Post a Comment