单击按钮时更改标签的文本

时间:2015-02-04 07:05:27

标签: c#

我是C#的新手。我需要lblBalance的文字在点击btnNew时保持原样,而当点击btnCalc时,它会根据某些计算值发生变化。这是我到目前为止的尝试。

计算出来,谢谢!

    private void btnReset_Click(object sender, EventArgs e)
    {
        //Reset balance to 0.
        balance = 0m;
        lblBalance.Text = "";
        tbDate.Text = "";
        //Call the setupForm procedure.
        setupForm();
    }
    private void setupForm()
    {
        //Setupform done once to reduce amount of times code must be entered.
        //Code to clear these entries and set radio and checkboxes to false.
        tbDate.Text = "";
        tbAmount.Text = "";
        rDeposit.Checked = false;
        rWithdrawal.Checked = false;
        rFee.Checked = false;
        chkBank.Checked = false;

        //Return focus to the date textbox
        tbDate.Focus();
    }

    private void btnNew_Click(object sender, EventArgs e)
    {
        //Clear form, but retain balance when clicked.


        setupForm();
    }

    private void tbDate_TextChanged(object sender, EventArgs e)
    {
    }




    private void lblBalance_Click(object sender, EventArgs e)
    {

    }

    private void btnCalc_Click(object sender, EventArgs e)
    {

        decimal Amount;

        Amount = decimal.Parse(tbAmount.Text);

        if ((rDeposit.Checked == true) && (chkBank.Checked == true))
        {

           Decimal.TryParse(lblBalance.Text, out balance);
           lblBalance.Text = Convert.ToString(balance + Amount);
        }

        else if ((rWithdrawal.Checked == true) && (chkBank.Checked == true))
        {
            Decimal.TryParse(lblBalance.Text, out balance);
            lblBalance.Text = Convert.ToString(balance - Amount);
        }
        else if ((rFee.Checked == true) && (chkBank.Checked == true))
        {
            Decimal.TryParse(lblBalance.Text, out balance);
            lblBalance.Text = Convert.ToString(balance - Amount);
        }

        if ((rDeposit.Checked == false) && (rWithdrawal.Checked == false) && (rFee.Checked == false))
        {
            MessageBox.Show("ERROR:  You must select Deposit, Withdrawal, or Service Fee.");
        }





    }

    private void rDeposit_CheckedChanged(object sender, EventArgs e)
    {


    }
}

}

1 个答案:

答案 0 :(得分:1)

变化:

lblBalance.Text += balance.ToString();

lblBalance.Text = balance.ToString(); 

btnNew_Click活动中