using System; using System.Windows.Forms; using System.Drawing; using System.Threading; class MainForm : Form { static void Main() { Application.ThreadException += new ThreadExceptionEventHandler(ExceptionHandler); Application.Run(new MainForm()); } static void ExceptionHandler(object sender, ThreadExceptionEventArgs args) { MessageBox.Show(args.Exception.ToString()); Application.Exit(); } Button btnDeposit; Button btnWithdraw; Button btnRead; TextBox txtAmount; Label lblAmount; Label lblResult; IAccount account; public MainForm() { this.ClientSize = new Size(300, 130); this.Text = "Bank Account"; this.Load += new EventHandler(this_Load); btnDeposit = new Button(); btnDeposit.Text = "Deposit"; btnDeposit.Location = new Point(10, 10); btnDeposit.Click += new EventHandler(btnDeposit_Click); btnWithdraw = new Button(); btnWithdraw.Text = "Withdraw"; btnWithdraw.Location = new Point(110, 10); btnWithdraw.Click += new EventHandler(btnWithdraw_Click); btnRead = new Button(); btnRead.Text = "Read"; btnRead.Location = new Point(210, 10); btnRead.Click += new EventHandler(btnRead_Click); lblAmount = new Label(); lblAmount.Text = "Amount:"; lblAmount.Location = new Point(10, 50); txtAmount = new TextBox(); txtAmount.Location = new Point(110, 50); txtAmount.Width = 170; lblResult = new Label(); lblResult.BorderStyle = BorderStyle.FixedSingle; lblResult.Location = new Point(10, 90); lblResult.Width = 270; this.Controls.AddRange( new Control[]{btnDeposit, btnWithdraw, btnRead, txtAmount, lblAmount, lblResult}); } void this_Load(object sender, EventArgs args) { account = new Account(); } void btnDeposit_Click(object sender, EventArgs args) { account.Deposit(Single.Parse(txtAmount.Text)); } void btnWithdraw_Click(object sender, EventArgs args) { account.Withdraw(Single.Parse(txtAmount.Text)); } void btnRead_Click(object sender, EventArgs args) { lblResult.Text = account.Read().ToString(); } }