📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace TheBank
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox account;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ComboBox action;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox amount;
private System.Windows.Forms.Button submit;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
private CheckingAccount checking = new CheckingAccount("Your Name");
private System.Windows.Forms.Button addInterest;
private SavingsAccount savings = new SavingsAccount("Your Name");
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.account = new System.Windows.Forms.ComboBox();
this.label2 = new System.Windows.Forms.Label();
this.action = new System.Windows.Forms.ComboBox();
this.label3 = new System.Windows.Forms.Label();
this.amount = new System.Windows.Forms.ComboBox();
this.submit = new System.Windows.Forms.Button();
this.addInterest = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 24);
this.label1.Name = "label1";
this.label1.TabIndex = 0;
this.label1.Text = "Account";
//
// account
//
this.account.DropDownWidth = 248;
this.account.Location = new System.Drawing.Point(128, 24);
this.account.Name = "account";
this.account.Size = new System.Drawing.Size(248, 21);
this.account.TabIndex = 1;
this.account.SelectedIndexChanged += new System.EventHandler(this.account_SelectedIndexChanged);
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 72);
this.label2.Name = "label2";
this.label2.TabIndex = 0;
this.label2.Text = "Action";
//
// action
//
this.action.DropDownWidth = 248;
this.action.Items.AddRange(new object[] {
"Deposit",
"Withdraw"});
this.action.Location = new System.Drawing.Point(128, 72);
this.action.Name = "action";
this.action.Size = new System.Drawing.Size(248, 21);
this.action.TabIndex = 1;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 120);
this.label3.Name = "label3";
this.label3.TabIndex = 0;
this.label3.Text = "Amount";
//
// amount
//
this.amount.DropDownWidth = 248;
this.amount.Location = new System.Drawing.Point(128, 120);
this.amount.Name = "amount";
this.amount.Size = new System.Drawing.Size(248, 21);
this.amount.TabIndex = 1;
//
// submit
//
this.submit.Location = new System.Drawing.Point(16, 176);
this.submit.Name = "submit";
this.submit.TabIndex = 2;
this.submit.Text = "Submit";
this.submit.Click += new System.EventHandler(this.submit_Click);
//
// addInterest
//
this.addInterest.Location = new System.Drawing.Point(128, 176);
this.addInterest.Name = "addInterest";
this.addInterest.TabIndex = 3;
this.addInterest.Text = "Add interest";
this.addInterest.Visible = false;
this.addInterest.Click += new System.EventHandler(this.addInterest_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(392, 222);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.addInterest,
this.submit,
this.label3,
this.amount,
this.label2,
this.action,
this.account,
this.label1});
this.Name = "Form1";
this.Text = "The Bank";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.account.Items.Add(checking);
this.account.Items.Add(savings);
this.account.SelectedIndex = 0;
this.action.SelectedIndex = 0;
this.amount.Text = "100";
}
private void submit_Click(object sender, System.EventArgs e)
{
BankAccount selectedAccount;
object item =this.account.SelectedItem;
selectedAccount =(BankAccount)item;
switch (action.Text){
case "Deposit" :
selectedAccount.Deposit(decimal.Parse(amount.Text));
break;
case "Withdraw" :
selectedAccount.Withdraw(decimal.Parse(amount.Text));
break;
}
MessageBox.Show(String.Format("{0}:{1:C}",
selectedAccount.ID,selectedAccount.Balance));
}
private void account_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (account.SelectedItem is SavingsAccount)
{
addInterest.Visible = true;
}
else
{
addInterest.Visible = false;
}
}
private void addInterest_Click(object sender, System.EventArgs e)
{
SavingsAccount theSavings = account.SelectedItem as SavingsAccount;
if (theSavings != null){
theSavings.AddInterest();
MessageBox.Show(String.Format("{0}:{1:C}", theSavings.ID,
theSavings.Balance));
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -