I have 2 forms, One is is MainProgram.cs for the MainProgram Form. Second, AddNewUser.cs for the NewUser Form. In MainProgram there is a button to open up NewUser which I open by using this code in MainProgram.cs
private void addNew_Button_Click(object sender, EventArgs e)
{
AddNewUser addUserForm = new AddNewUser();
addUserForm.Show();
}
The method I'm calling is to reset the textfields in and with the method in AddNewUser from MainProgram. This code is in AddNewUser.cs
public void ResetTextFields_NewUser()
{
textBox_Username.ResetText();
textBox_Password.ResetText();
}
This method works if called by a button in the same form. But when I try to call it from MainProgram it does not work. So something is wrong, I'm not initializing the correct way or referencing the existing class because it does work just not when I try to reference the class.
Here is the code in AddNewUser that calls MainProgram to then call AddNewUser again.
AddNewUser.cs inside a Button in the Form
private void addNewUser_Button_Click(object sender, EventArgs e)
{
MainProgram mainForm = new MainProgram();
mainForm.Add_DataValues();
}
MainProgram.cs a public method inside the Form
public void Add_DataValues()
{
AddNewUser addUserForm = new AddNewUser();
addUserForm.ResetTextFields_NewUser();
// reason I'm going back and forth is because in this method im also using variables
// from MainProgram form and instead from grabbing it from AddNewUser.cs I just use it
// from the class itself and then call AddNewUser to reset the textfields
// by a simple public method. but its not working
}
Reason I think the problem is that I'm not referencing the existing class is because I added a MessageBox.Show("");
to all the methods on here and it all showed up so the code works but not to the existing class. Its creating a new one instead of referencing an existing one.