如何将私有属性中的double值传递给另一个私有属性 [英] How to pass through a double value from a private properties to another private properties

查看:79
本文介绍了如何将私有属性中的double值传递给另一个私有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

i have try to calculate the value of double month1 and its successful...

private void dateTimePicker1_ValueChanged(object sender,EventArgs e)
{
DateTime from = dateTimePicker1.Value;
DateTime to = DateTime.Now;
TimeSpan TSpn = to - from;
双月= TSpn.TotalDays;
txtMonths.Text =(month / 31).ToString(" 0"" months");
double month1 =(month / 31);

}

private void button1_Click(object sender,EventArgs e)
{
if(txtName.Text =="" || txtName .Text.Length> = 16)
{
MessageBox.Show(" Error:Name blank or too long。""" Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}

if(txtCode.Text =="" || txtCode.Text.Length> = 7 || txtCode.Text.Length< = 5)
{
MessageBox.Show(" Error:Code blank or 6 digit available only。""" Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
}

if(txtMonthlyFee.Text ==" 30")
{
double num1 = month1;
double no1 = 30;
double sum1 = num1 + no1;
txtSubTotal.Text = sum1.ToString(" 0");
txtTotalPay.Text = sum1.ToString(" 0");
}
}

private void dateTimePicker1_ValueChanged(object sender, EventArgs e) { DateTime from = dateTimePicker1.Value; DateTime to = DateTime.Now; TimeSpan TSpn = to - from; double month = TSpn.TotalDays; txtMonths.Text = (month / 31).ToString("0" + " months"); double month1 = (month / 31); } private void button1_Click(object sender, EventArgs e) { if (txtName.Text == "" ||txtName.Text.Length >= 16) { MessageBox.Show("Error: Name blank or too long.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); } if (txtCode.Text == "" || txtCode.Text.Length >= 7 || txtCode.Text.Length <= 5) { MessageBox.Show("Error: Code blank or 6 digit available only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (txtMonthlyFee.Text == "30") { double num1 = month1; double no1 = 30; double sum1 = num1 + no1; txtSubTotal.Text = sum1.ToString("0"); txtTotalPay.Text = sum1.ToString("0"); } }

但是如何从 private void dateTimePicker1_ValueChanged to private void button1_Click以便双num1来自private void button1_Click可以读取值.?

推荐答案

class MyClass : Form
{
private double month1;

private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
        {
            DateTime from = dateTimePicker1.Value;
            DateTime to = DateTime.Now;
            TimeSpan TSpn = to - from;
            double month = TSpn.TotalDays;
            txtMonths.Text = (month / 31).ToString("0" + " months");
            month1 = (month / 31);
           
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtName.Text == "" ||txtName.Text.Length >= 16)
            {
                MessageBox.Show("Error: Name blank or too long.","Error",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

            if (txtCode.Text == "" || txtCode.Text.Length >= 7 || txtCode.Text.Length <= 5)
            {
                MessageBox.Show("Error: Code blank or 6 digit available only.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (txtMonthlyFee.Text == "30")
            {
                double num1 = month1;
                double no1 = 30;
                double sum1 = num1 + no1;
                txtSubTotal.Text = sum1.ToString("0");
                txtTotalPay.Text = sum1.ToString("0");
            }
        }
}
}








这篇关于如何将私有属性中的double值传递给另一个私有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆