Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Getting Values From a Method In A Form Into Another Form
- public class Form1 : Form
- {
- private string user_code;
- public string UserCode
- {
- get { return user_code; }
- }
- public bool LoginUser()
- {
- user_code = null;
- if(textBox1.Text=="123"){
- user_code="usercode";
- }
- *
- */
- }
- }
- Form1 form1 = new Form1();
- form1.LoginUser();
- MessageBox.Show(form1.UserName);
- objfrm1.loginuser(out U, out v, out w, out a,out b, out c);
- public class Form1 : Form
- {
- private string user_pass;
- private string user_name;
- private bool insert_ability;
- private bool update_ability;
- private bool delete_ability;
- public string UserPass
- {
- get { return user_pass; }
- }
- public string UserName
- {
- get { return user_name; }
- }
- public bool InsertAbility
- {
- get { return insert_ability; }
- }
- public bool UpdateAbility
- {
- get { return update_ability; }
- }
- public bool DeleteAbility
- {
- get { return delete_ability; }
- }
- public bool LoginUser()
- {
- /*
- Your code here
- user_pass = "userpass";
- user_name = "username";
- insert_ability = true;
- update_ability = false;
- delete_ability = false;
- *
- */
- }
- }
- Form1 form1 = new Form1();
- form1.LoginUser();
- MessageBox.Show(form1.UserName);
- public class Form1 : Form
- {
- private string user_code;
- public string UserCode
- {
- get { return user_code; }
- }
- private string _testData; //THIS IS NEEDED
- public string TestData //THIS IS NEEDED
- {
- set { _testData = value;} //THIS IS NEEDED
- }
- public bool LoginUser()
- {
- user_code = null;
- if(textBox1.Text=="123" || TestData=="123") //THIS IS NEEDED
- {
- user_code="usercode";
- }
- }
- }
- Form1 form1 = new Form1();
- form1.TestData = "123"; //THIS IS NEEDED
- form1.LoginUser();
- MessageBox.Show(form1.UserName);
- class FormLogin : Form
- {
- public string UserName
- {
- get { return textBoxUserName.Text; }
- set { textBoxUserName.Text = value; }
- }
- public string Password
- {
- get { return textBoxPassword.Text; }
- set { textBoxPassword.Text = value; }
- }
- public FormLogin()
- {
- this.Closing += new System.ComponentModel.CancelEventHandler(FormLogin_Closing);
- }
- void FormLogin_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- if (this.DialogResult == DialogResult.Cancel) return;
- if (!LoginUser(UserName, Password))
- {
- MessageBox.Show("Username or password is incorrect");
- e.Cancel = true;
- }
- }
- bool LoginUser(string userName, string password)
- {
- // check login and password in database for example
- return true;
- }
- }
- class Form3 :Form
- {
- void LoginButtonClick()
- {
- FormLogin formLogin = new FormLogin();
- formLogin.UserName = "LastUserName";
- //uncomment if you want hide main form
- //this.Hide();
- if (formLogin.ShowDialog() == DialogResult.OK)
- {
- MessageBox.Show(string.Format("Congratulation! You are logged as {0}", formLogin.UserName));
- }
- //this.Show();
- }
- }
Add Comment
Please, Sign In to add comment