I am currently trying to have a pop up form and when I click a button it pops up. When it does you enter your information then send it back.
Note there might be some errors because it is not copy and paste. I only included the code that matters
Form1:
namespace estController
{
public partial class MainForm : Form
{
string Tempcustomer = "";
string TempManager = "";
string TempManagerId = "";
string TempName = "";
string TempProjectId = "";
string TempSharePointID = "";
string Tempstatus = "";
private void buttonBegin_Click(object sender, EventArgs e)
{
if(ManualEnterNumber.Checked)
{
buttonBegin.Enabled = false;
Manual_Input F2 = new Manual_Input();
F2.Show();
}
}
private void buttonNext_Click(object sender, EventArgs e)
{
MessageBox.Show("test" + TempName);
}
internal void receiveData(string boxCustomer, string boxManager, string boxManagerId, string boxName, string boxProjectId, string boxSharePointId, string boxStatus)
{
Tempcustomer = boxCustomer;
TempManager = boxManager;
TempManagerId = boxManagerId;
TempName = boxName;
TempProjectId = boxProjectId;
TempSharePointID = boxSharePointId;
Tempstatus = boxStatus;
}
}
}
Form 2:
namespace estController
{
public partial class Manual_Input : Form
{
private void buttonEnter_Click(object sender, EventArgs e)
{
MainForm Form = new MainForm();
Form.receiveData(boxCustomer.Text, boxManager.Text, boxManagerId.Text, boxName.Text, boxProjectId.Text, boxSharePointId.Text, boxStatus.Text);
this.Close();
}
}
}
What I expect to happen is to click the begin button. When that happen form 2 opens and I enter the data needed. Next I hit the button to send the data then close the form. The data should be saved in the variables that are initialized at the beginning of form1. Finally I can click the next button and check the data is there.
When stepping through the code I can see that data being assigned but when I then hit the next button the data is gone.
This is creating a new instance of
MainForm:That instance is not the same as the instance you just came from. Consider an analogy:
You can pass a reference to the object when creating an instance of
Manual_Input. For example, add this constructor toManual_Input:This will require that newly created instances of
Manual_Inputneed a reference to aMainForm, since they internally depend on one to perform their tasks. Pass that reference when creating the instance:Then you can use that reference when performing the logic in
Manual_Input: