Error: Passing textbox value to another form

  • Thread starter Thread starter VA_er
  • Start date Start date
V

VA_er

Guest
It is Mdi application, both FormLogin and FormDestination are child forms, I am trying to pass value from FormLogin to FormDestination, but I could not rebuild the solution, how to fix the error? Both screenshot and code are attached.

Thanks.

namespace Demo
{
public partial class FormLogin : Form
{
public FormLogin()
{
InitializeComponent();
}

private void FormLogin_Load(object sender, EventArgs e)
{
txtUsername.Text = Environment.UserName;
this.ActiveControl = txtPassword;
}

public string Username
{
get { return txtUsername.Text; }
}

public string Password
{
get { return txtPassword.Text; }
}

private void button1_Click(object sender, EventArgs e)
{
FormDestination fDestination = new FormDestination();
fDestination.Show();
this;
}
}

}

namespace Demo
{
public partial class FormDestination : Form
{
public FormDestination()
{
InitializeComponent();
}

private void DisplayUsernameAndPassword_Click(object sender, EventArgs e)
{
FormLogin fLogin = new FormLogin();
fLogin.ShowDialog(this); // make sure this instance of FormLogin is visible
MessageBox.Show("Username = " + fLogin.Username + "; Password = " + fLogin.Password);
}
}
}



1413597.jpg

Continue reading...
 
Back
Top