newbie question Passing veriable between two forms, it's a string "LoggedUserName"
I have MainForm that starts LoggingFrm:
public void Form1_Load(object sender, EventArgs e)
{
LoggingFrm newLogin = new LoggingFrm();
newLogin.ShowDialog();
if(string.IsNullOrEmpty(newLogin.LoggedUser))
{
Close();
}
else
{
User = newLogin.LoggedUser;
tsslUser.Text = Uzytkownik;
LoggedUser = User;
}
}
And logging frm:
private string User;
public string LoggedUser
{
get
{
return User;
}
set
{
User = value;
}
}
private void btnLogIn_Click(object sender, EventArgs e)
{
String user = tbUser.Text;
String pass = tbPassword.Text;
if (IsLogin(user, pass)) // Mysql code behind
{
MessageBox.Show($"Logged as {user}!");
LoggedUser = tbUser.Text; //Setting public string
Close();
}
else
{
MessageBox.Show($"User {user} not found!");
}
}
and third form with
LoggingFrm frm = new LoggingFrm();
lblTest.Text = frm.LoggedUser
And at that point it works fine, but if I try to transfer the string to any different form it doesn't work - string is null.
no matter if I try to pass it from LoggingFrm or MainFrm
Any ideas?