I need to call some methods from one class to another class in c#. Its different from the other answers that are put up as i cant seem to find the specific answer i am looking for.
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 IT2127P2_150538B
{
public partial class InputForm : Form
{
const double cupCakePrice = 1.50;
int noOfCupcakes, loyaltyPoints;
double TotalPrice;
int[] price = new int[15];
public InputForm()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Form Summaryform = new SummaryForm();
Summaryform.ShowDialog();
noOfCupcakes = int.Parse(txtNoOfCupcakes.Text);
TotalPrice = noOfCupcakes * cupCakePrice;
if (txtMemId.Text != "")
{
if ( noOfCupcakes / 2 > 0)
{
loyaltyPoints = (((noOfCupcakes - 1) / 2) * 3) + 1;
}
else
{
loyaltyPoints = (noOfCupcakes / 2) * 3;
}
}
else
{
loyaltyPoints = 0;
}
}
}
}
}
The code above is the main class where the computation is done. Now i have to display number of cupcakes, loyalty points and total cupcake price in the code below. My problem is that i cant seem to find a way to call the variables in the primary class to the secondary class.
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 IT2127P2_150538B
{
public partial class SummaryForm : Form
{
const double cupcakePrice = 1.50;
public SummaryForm()
{
InitializeComponent();
}
private void SummaryForm_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}