Visual Studio 2005
Windows Forms Application
GUI


Form1:entering name, then log-in
Form2: main interface

I want to show the log-in name on Form2 at a certain place. So every time a different person uses the program, it shows the log-in name on the interface.

How to pass the input of a textbox in Form1 onto Form2?

Assuming that your login form is a modal dialog, you can associate
- a class to that dialog (if I remember correctly, this is done when you add the dialog)
- member variables of this clas to the edit boxes in that dialog.
When user has entered the data and clicks Ok, in OnOk() you can use DDX to (think the function name was UpdateData() ) get the values from edit boxes to associated variables.
Also I assume that to show the dialog box you use loginDialogObj.doModal() from your main form. So you already have the values (loginDialogObj.userName, loginDialogObj.xxx).

> How to pass the input of a textbox in Form1 onto Form2?
I guess it depends on how you open the forms. If Form2 is the main form and controls Form1, you can use a property to get the login name:

// Put this in Form1
property String^ LoginName {
  String^ get() { return textBoxName->Text; }
}

// This says whether the login failed or succeeded
property bool Authenticated {
  bool get() { return _isAuthenticated; }
}

Edward usually does something like this in the Form2 load event:

void Form2_Load(Object^ sender, EventArgs^ e)
{
  Form1^ login = gcnew Form1();

  if (login->ShowDialog() != ::DialogResult::OK
    || !login->Authenticated) {

    Application->Exit();
  }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.