I have 2 forms:
- frmLogIn
- frmMainForm
frmLogin has 2 textboxes:
- txtUserName
- txtPassword.
frmMainForm has 1 label:
- lblGreetings
the idea is that if you will enter your username w/ its corresponding password, in the main form (frmMainForm), there should be a welcoming message using the lblGreetings, such as:
WELCOME, (username)!
the idea should be something like:
txtUserName.Text = lblGreetings.Text
but as you can see, you just cannot read the value from one form to another, not unless you're going to instantiate the form itself, isn't?
is it possible that I can add such status in the main form?
does the frmMainForm_Load should have:
frmLogin form = new frmLogin()
form.? << what is next?
any ideas?
AlanPosted Mar 31, 2008, 11:27 AM
Assuming that frmMainForm is launched by code in frmLogin, following a sucessful log in, I'd just pass the user name in the constructor;
// in frmLogin something like
frmMainFrom mainForm = new frmMainForm(txtUserName.Text);
mainForm.Show();
// in frmMainForm change constructor to:
public frmMainForm(string userName)
{
InitializeComponent();
lblGreetings.Text = "WELCOME, " + userName +"!";
}