利息计算器(interest calculator)

来源:互联网 发布:windows system 编辑:程序博客网 时间:2024/05/01 21:19

实现简单的基于GUI的利息计算器:

namespace interest_calculator{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void calculatorBtn_Click(object sender, EventArgs e)        {            decimal principal, toal;            double rate, time;            try            {                principal = Convert.ToDecimal(textBox1.Text);                rate = Convert.ToDouble(textBox2.Text);                 time = Convert.ToDouble(textBox3.Text);            }            //Exception Handling            catch (Exception)             {                MessageBox.Show("输入数据不正确,请检查!");                textBox1.Clear();                textBox2.Clear();                textBox3.Clear();                return;            }            if (principal < 0 || rate < 0 || time < 0)            {                MessageBox.Show("输入数据应该为正数,请检查!");                textBox1.Clear();                textBox2.Clear();                textBox3.Clear();                return;            }            if (calculatorRadioBtn_1.Checked)            {                toal = principal + principal * (decimal)((rate / 100) * time);  //计算单利                showBox.Text = Convert.ToString(toal);            }            else            {                toal = principal * (decimal)Math.Pow(1 + rate / 100, time); //计算复利                showBox.Text = Convert.ToString(toal);            }        }        private void resetBtn_Click(object sender, EventArgs e)        {            textBox1.Clear();   //重置将清除textBox和showBox之前的输入            textBox2.Clear();            textBox3.Clear();            showBox.Clear();        }        private void Form1_KeyDown(object sender, KeyEventArgs e)        {            //设置按钮快捷键            if (e.KeyCode == Keys.C && e.Control)                calculatorBtn.PerformClick();              if (e.KeyCode == Keys.R && e.Control)                resetBtn.PerformClick();            if (e.KeyCode == Keys.E && e.Control)                quitBtn.PerformClick();        }        private void quitBtn_Click(object sender, EventArgs e)        {            this.Close(); //退出程序        }    }}

代码地址:http://download.csdn.net/download/github_37588138/10157223

原创粉丝点击