I have made this form and my teacher wants me to change some of my code to where Each of the mortgage calculations which are presently in the Execute Button Click event are to be moved into their own method which will be called in the button click event.
What I need help with is how do I do this action any help will be awesome.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Chapter06Exercise03_Base
{
    public partial class frmMortgage : Form
    {
        public frmMortgage()
        {
            InitializeComponent();
        }

        private void btnExecute_Click(object sender, EventArgs e)
        {
            decimal dIRate = .005m;
            decimal dYears15 = 15m;
            decimal dYears20 = 20m;
            decimal dYears30 = 30m;
            decimal dMonths = 0m;
            decimal dMonthlyPayment = 0m;
            decimal dLoanAmount = 0m;
            string szHolding = "";

            szHolding = txtUserInput.Text;

            dLoanAmount = Convert.ToDecimal(szHolding);

            // Calculate 15 year Mortgage Payment
            dMonths = dYears15 * 12m;

            dMonthlyPayment = dIRate * (decimal) Math.Pow((double)(1m + dIRate), (double)dMonths);
            dMonthlyPayment /= ((decimal)Math.Pow((double)(1m + dIRate), (double)dMonths) - 1m);
            dMonthlyPayment *= dLoanAmount;

            Payment15.Text = dMonthlyPayment.ToString("C");

            // Calculate 20 year Mortgage Payment
            dMonths = dYears20 * 12m;

            dMonthlyPayment = dIRate * (decimal)Math.Pow((double)(1m + dIRate), (double)dMonths);
            dMonthlyPayment /= ((decimal)Math.Pow((double)(1m + dIRate), (double)dMonths) - 1m);
            dMonthlyPayment *= dLoanAmount;

            Payment20.Text = dMonthlyPayment.ToString("C");

            // Calculate 30 year Mortgage Payment
            dMonths = dYears30 * 12m;

            dMonthlyPayment = dIRate * (decimal)Math.Pow((double)(1m + dIRate), (double)dMonths);
            dMonthlyPayment /= ((decimal)Math.Pow((double)(1m + dIRate), (double)dMonths) - 1m);
            dMonthlyPayment *= dLoanAmount;

            Payment30.Text = dMonthlyPayment.ToString("C");

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            Payment15.Text = "";
            Payment20.Text = "";
            Payment30.Text = "";
        }

        private void frmMortgage_Load(object sender, EventArgs e)
        {

        }

        private void lblUserInput_Click(object sender, EventArgs e)
        {

        }

        private void txtUserInput_TextChanged(object sender, EventArgs e)
        {

        }

        private void lbl15year_Click(object sender, EventArgs e)
        {

        }

        private void Payment15_Click(object sender, EventArgs e)
        {

        }

        private void lbl20year_Click(object sender, EventArgs e)
        {

        }

        private void Payment20_Click(object sender, EventArgs e)
        {

        }

        private void lbl30year_Click(object sender, EventArgs e)
        {

        }

        private void Payment30_Click(object sender, EventArgs e)
        {

        }

    }
}

Make a method like this:

public double Mortgage(int months, double dIRate, double loanamount)
{
    //3 lines of your calculations
    return Montly payments
}

Next replace your calculations in the click event with a call to Mortgage

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.