我正在 Windows 窗体上测试一个银行帐户。一些容易开始的事情。在我dep_Click
的方法中,我有一种方法,如果我点击它,我会在aMtBox
. 我想进一步扩展并尝试创建一个具有一些属性等的 BankAccount 类。我使用我的withdrawl_Click
方法来尝试这样做。我看到的一切看起来在控制台应用程序中都可以,除了我不知道如何调用 ; 中的方法withdrawl_Click
。也就是说,我是否能够使用我编写的代码。
代码是否完全错误并且 Windows 窗体应用程序中的某些内容有所不同?或者有没有我/没有理解的概念。请向我解释并清楚地说明这一点。
编辑:我更新了我的代码,但是它仍然给我一个关于withDrawl
在底部附近的方法中需要返回类型的错误。仍然不确定。
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(iBa, num1);
public Form1()
{
InitializeComponent();
decimal iBa = 300.00m; // needs fixed to be more universal
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);
}
}
private void withdrawl_Click(object sender, EventArgs e)
{
}
public class BankAccount
{
decimal iBa;
decimal num1;
decimal withT;
public decimal IBa
{
get
{
return iBa;
}
}
public decimal Num1
{
get
{
return num1;
}
}
public decimal Witht
{
get
{
return withT;
}
}
public withDrawl(decimal n, decimal s )
{
iBa = n;
num1 = s;
withT = iBa - num1;
}
}
}
}