问题出在
num1 = Convert.ToDecimal(this.withBox.Text);
的bankAccount()
我正在尝试将其设置为您可以在 withBox 文本框中输入任何小数点的位置,当您单击按钮时,它将为您提供aMtBox
. 我不确定我做错了什么。
是给我这个错误,但我不知道为什么?
我想要的是让 num1 等于我在 withBox 中输入的任何内容。那是我的最终目标。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
BankAccount a = new BankAccount();
public Form1()
{
InitializeComponent();
decimal iBa = 300.00m;
this.aMtBox.Text = iBa.ToString();
}
private void dep_Click(object sender, EventArgs e)
{
try
{
decimal num1 = 0.00m;
decimal iBa = 300.00m;
num1 = Convert.ToDecimal(this.depBox.Text);
decimal total = num1 + iBa;
this.aMtBox.Text = total.ToString();
}
catch
{
MessageBox.Show("ERROR", "Oops, this isn't good!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
public void withdrawl_Click(object sender, EventArgs e)
{
this.aMtBox.Text = a.Balance.ToString();
}
public class BankAccount
{
decimal balance;
decimal iBa;
decimal num1;
public decimal Balance
{
get { return balance; }
}
public decimal IBa
{
get { return iBa; }
}
public decimal Num1
{
get { return num1; }
}
public BankAccount()
{
iBa = 300.00m;
num1 = Convert.ToDecimal(this.withBox.Text);
balance = iBa - num1;
}
}
private void withBox_TextChanged(object sender, EventArgs e)
{
}
}
}