private void Account_Overdrawn(object sender, OverDrawnArgs e) { // Get the account. BankAccount account = sender as BankAccount; // Ask the user whether to allow this. if (MessageBox.Show("Insufficient funds.\n\n Current balance: " + account.Balance.ToString("C") + "\n Debit amount: " + e.DebitAmount.ToString("C") + "\n\n" + "Do you want to allow this transaction anyway?", "Allow?", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { // Allow the transaction anyway. e.allow = true; } }
public void Debit(decimal amount) { if (amount < 0) { throw new ArgumentOutOfRangeException("Debit amount must be positive."); } if (Balance >= amount) { Balance -= amount; } else { if (Overdrawn != null) { OverDrawnArgs args = new OverDrawnArgs(); args.DebitAmount = amount; Overdrawn(this, args); } } }