As per my previous post. I got it working correctly.
In the welcome screen, the user enters his/her details. Like name and surname. Then the user clicks the next button. The welcome screen closes and the main window opens.
However, the name and surname are no longer accessible in the main.cs file.
The welcome screen code:
public string username;
public string usersurname;
static private Form Sender;
static public void Run(Form sender)
{
if (sender == null)
throw new ArgumentNullException();
Sender = sender;
new WelcomeForm().ShowDialog();
}
public WelcomeForm()
{
InitializeComponent();
}
private void sign_in_Click(object sender, EventArgs e)
{
username = textBox1.Text;
usersurname = textBox2.Text;
Close();
}
My Main window code:
private void Form1_Load(object sender, EventArgs e)
{
WelcomeForm.Run(this);
}
public Form1()
{
InitializeComponent();
}
How do I get access to username and usersurname in my main.cs file as well?
Updated Code (Welcome screen):
private WelcomeFormInputData InputData = new WelcomeFormInputData();
static private Form Sender;
static public WelcomeFormInputData Run(Form sender)
{
if (sender == null)
throw new ArgumentNullException();
Sender = sender;
var form = new WelcomeForm();
return form.ShowDialog() == DialogResult.OK ? form.InputData : null;
}
private void ButtonValidate_Click(object sender, EventArgs e)
{
InputData.UserName = textBox1.Text;
InputData.UserSurname = textBox2.Text;
DialogResult = DialogResult.OK;
Close();
}
public WelcomeForm()
{
InitializeComponent();
}
public class WelcomeFormInputData
{
public string UserName { get; set; }
public string UserSurname { get; set; }
}