using System;
using System.Windows.Forms;
namespace MajorProject1_2
{
public partial class Form1 : Form
{
private double totalLoan;
private double mounthsCounter;
private string formatstring;
private object accumulate1;
private object accumulate2;
private int months;
private object answer;
public double TotalInterest { get; private set; }
public double TotalPP { get; private set; }
public object Value { get; private set; }
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e)
{
}
private void label5_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
accumulate1 = Value;
accumulate2 = Value;
listBox1.Items.Clear();
textBox1.Clear();
comboBox2.Items.Clear();
checkBox1.Checked = false;
if (radioButton1.Checked)
months = 6;
textBox2.Enabled = false;
textBox1.Focus();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged_1(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
double loan, rate, rebate, months, principalPayment, interest, pmt;
try
{
double.TryParse(textBox1.Text, out loan);
rate = Convert.ToDouble(comboBox2.Text);
double.TryParse(textBox2.Text, out rebate);
if (radioButton1.Checked)
months = 6;
if (radioButton2.Checked)
months = 12;
if (radioButton3.Checked)
months = 18;
if (radioButton4.Checked)
months = 24;
}
catch {
MessageBox.Show("Please select one from the box!", "Error Message",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
groupBox1.Focus();
}
double.TryParse(textBox1.Text, out loan);
rate = Convert.ToDouble(comboBox2.Text);
if (loan == 0)
{
MessageBox.Show("Please enter loan amount and annual APR.", "Error Message",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
textBox1.Focus();
}
if (rate == 0)
MessageBox.Show("Please enter loan amount and annual APR.", "Error Message",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
comboBox2.Focus();
if (checkBox1.Checked)
double.TryParse(textBox2.Text, out rebate);
rebate = 0;
loan = loan - rebate;
rate = rate / 100;
months = 0;
principalPayment = rate / 12 * (loan + 0 * Math.Pow(1 + rate / 12, months)) / ((Math.Pow(1 + rate /
12, months) - 1) * (1 + rate / 12 * 0));
interest = loan * rate / 12;
string formatString = "{0,5}{1,12}{2,12}{3,12}{4,12}";
for (int monthsCounter = 1; mounthsCounter <= months; monthsCounter = monthsCounter + 1)
{
pmt = principalPayment + interest;
loan = principalPayment - loan - rebate;
listBox1.Items.Add(String.Format(formatString, monthsCounter, interest.ToString("C"), principalPayment.ToString("N"), pmt.ToString("N"), loan.ToString("N")));
totalLoan += loan;
TotalInterest += interest;
TotalPP += principalPayment;
interest = loan * rate / 12;
principalPayment = pmt - interest;
}
listBox1.Items.Add("{0,5}{1,12}{2,12}{3,12}{4,12}");
listBox1.Items.Add(String.Format(formatString, interest.ToString("C"), principalPayment.ToString("N"), loan.ToString("N")));
{
listBox1.Items.Add("");
listBox1.Items.Add(String.Format(formatString, interest.ToString("C"), principalPayment.ToString("N"), loan.ToString("N")));
}
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.SelectAll();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
const string message = "Are you sure you want to exit?";
const string caption = "Exit";
var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.Yes)
{
Application.Exit();
}
else if (result == DialogResult.Yes)
{
this.Close();
}
}
private void textBox2_TextChanged_1(object sender, EventArgs e)
{
}
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
}
private void label9_Click(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
double accumulate1 = double.Parse(textBox3.Text);
double accumulate2 = double.Parse(textBox4.Text);
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
What I have tried:
I have tried multiple ways to display code into the listbox but none of them are working.