Мне нужно работать с именем пользователя в любой другой форме приложения. Я заполнил следующую форму входа, но не знаю, как отправить имя пользователя в другие формы. Есть какие-нибудь советы?
Thread th;
public void openMainForm(object obj)
{
Application.Run(new MainForm());
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection conLogin = new SqlConnection(conString);
SqlCommand sqlLogin = new SqlCommand(sqlString,conLogin);
SqlDataReader dr;
conLogin.Open();
dr = sqlLogin.ExecuteReader();
while (dr.Read())
{
if (txtUser.Text.Equals(dr[0].ToString()) && txtPassword.Text.Equals(dr[1].ToString()))
{
this.Close();
th = new Thread(openMainForm);
th.SetApartmentState(ApartmentState.STA);
th.Start();
}
else
{
MessageBox.Show("Invalid Data", "Invalid Username/Password", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUsername.Clear();
txtPassword.Clear();
txtUsername.Focus();
}
}
conLogin.Dispose();
}
Подробнее здесь: https://stackoverflow.com/questions/707 ... pplication