I'm working with two forms. One is a login form and the other is a detail form. I'm trying to pass the objects that were obtained from login such as username and id# to the details, so that when the enter button is pressed, the details form loads with the greeting, "Hello [username + id#]! at the title bar of the form.
This is what I have started---
Form1:
public partial class Login : Form
{
//Auto-Impl Properties
private Details de = new Details();
private void Login_Click(object sender, EventArgs e)
{
GetInputs();
//validate inputs
de.ShowDialog(); //display the 2nd form
}
2nd form:
public partial class Details : Form
{
public string Fname { get; set; }
public string Lname { get; set; }
public string Unum { get; set; }
public Details()
{
InitializeComponent();
}
private void Details_Load(object sender, EventArgs e)
{
}
}
I also want to indicate that the Program.cs is set to run the Login
This code loads the 2nd form after the enter button is pressed but of course the objects from form1 is not passed.
Are you aware that you can add parameters to the form's constructor?
public Details(string userName)
{
InitializeComponent();
// set the title here
}
You can create the Details form after you got login data and pass the name in the constructor:
GetInputs();
// validate inputs
de = new Details("name");
de.ShowDialog();