あるクラスからいくつかのメソッドを別のクラスに呼び出す必要があります。私はそれが私が探している特定の答えを見つけることができないように置かれている他の答えとは異なる。あるクラスから別のクラスにメソッドを呼び出す方法
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;
}
}
}
}
}
上記のコードは、計算が行われるメインクラスです。今度は、以下のコードでカップケーキの数、ロイヤリティポイント、カップケーキの価格を表示する必要があります。私の問題は、プライマリクラスの変数をセカンダリクラスに呼び出す方法が見つからないようです。
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();
}
}
}
_「カップケーキの数、ポイントと総カップケーキの価格を下のコードで表示する必要があります。質問ありますか?何が問題なの?あなたの質問はほぼ確実にhttps://stackoverflow.com/questions/1665533/communicate-between-two-windows-forms-in-c-sharpの複製ですが、あなたは実際に尋ねています。この質問ははっきりしていません。 –