private void txtPrincipal_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { FormControlMethods.FormatTextBox((TextBox)sender); } }
// Calculates the fraction that is being saved. private void txtIncome_Leave(object sender, EventArgs e) { FormControlMethods.FormatTextBox((TextBox)sender); decimal income = decimal.Parse(txtIncome.Text, NumberStyles.Currency); decimal spending = decimal.Parse(txtSpending.Text, NumberStyles.Currency); decimal savings = income - spending; txtSavings.Text = savings.ToString("C2") + " (" + (savings / income * 100).ToString("0.0") + "%)"; }
private void txtStockFraction_Leave(object sender, EventArgs e) { FormControlMethods.FormatTextBox((TextBox)sender); double stockFraction = double.Parse(txtStockFraction.Text); double bondFraction = double.Parse(txtBondFraction.Text); if (sender.Equals(txtStockFraction)) { bondFraction = 100f - stockFraction; txtBondFraction.Text = bondFraction.ToString("0.0"); } else { stockFraction = 100f - bondFraction; txtStockFraction.Text = stockFraction.ToString("0.0"); } }
private void txtSpendingFractionGrowth_Leave(object sender, EventArgs e) { FormControlMethods.FormatTextBox((TextBox)sender); double savingsFraction = double.Parse(txtSavingFractionGrowth.Text); double spendingFraction = double.Parse(txtSpendingFractionGrowth.Text); if (sender.Equals(txtSavingFractionGrowth)) { spendingFraction = 100f - savingsFraction; txtSpendingFractionGrowth.Text = spendingFraction.ToString("0.0"); } else { savingsFraction = 100f - spendingFraction; txtSavingFractionGrowth.Text = savingsFraction.ToString("0.0"); } }
private void txtAge_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { FormControlMethods.FormatTextBox((TextBox)sender); if (sender.Equals(txtIncome) || sender.Equals(txtSpending)) { txtIncome_Leave(sender, e); } else if (sender.Equals(txtSpendingFractionGrowth) || sender.Equals(txtSavingFractionGrowth)) { txtSpendingFractionGrowth_Leave(sender, e); } else if (sender.Equals(txtStockFraction) || sender.Equals(txtBondFraction)) { txtStockFraction_Leave(sender, e); } } }
private void txtPrincipal_Leave(object sender, EventArgs e) { FormControlMethods.FormatTextBox((TextBox)sender); }
private void txtAge_Leave(object sender, EventArgs e) { FormControlMethods.FormatTextBox((TextBox)sender); txtSavingsGoal.Text = GetGoal(); }