Re: How can share the value between more Windows Forms ? by Danny
Danny
Mon Apr 04 02:34:10 CDT 2005
Kylin wrote:
> hi,
> Where the user input there Login Name and Password,
> and I want to remerber this values In maninform,
> and this values will be used by other form,
> eg: Change password Form,
> this need the user's name ,oldpassword, new password,
> and the user's name comes from the mainform.
>
> how can do for this ?
You could use properties, or parameters in the constructor. eg.
-- loginForm.cs --
MainForm frm = new MainForm(txtUser.Text, txtPass.Text);
frm.Show()
-- / --
-- MainForm.cs --
public MainForm(string user, string pass)
{
// Put user & pass into private fields
}
-- / --
Or alternatively, add some properties, so you can do
-- loginForm.cs --
MainForm frm = new MainForm();
frm.User = txtUser.Text;
frm.Pass = txtPass.Text
frm.Show()
-- / --
Though if you're doing it that way, a struct to hold the details might
be better:
-- loginForm.cs --
MainForm frm = new MainForm();
frm.UserDetails = new UserDetails(txtUser.Text, txtPass.Text);
frm.Show()
struct UserDetails
{
public string User, Pass;
public UserDetails (string user, string pass)
{
User = user;
Pass = pass;
}
}
-- / --
HTH
--
Danny