Hack Forums
[C#] closed closed closed closed - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] closed closed closed closed (/showthread.php?tid=5061679)



closed closed closed closed - ℓιℓ υzι νєят - Nov 17, 2015

closed closed closed closed


* - BahNahNah - Nov 17, 2015

Make some public properties in form1, then access them from the instance in form2.

In form2:
Code
form1 f1 = new form1();
f1.ShowDialog();

DoStuff(f1.Username, f1.Password);



* - Rhez - Nov 17, 2015

Form2_Load
Code
Textbox1.Text == Form1.Textbox1.Text



* - Odus - Nov 18, 2015

Third way is to accept them as args in your form's constructor and keep them private if you only need to pass and not constantly communicate between.


* - Rhez - Nov 18, 2015

(Nov 17, 2015 06:14 PM)Rʌv3ɲ Wrote:  I need help with somthing
So, in my form1 I got my login and I wanna get the username in the first textbox over to my form2 after logging in. How do I make it so I can get the username in a php script in the form2.

It's just the same in ur previous question. The answer is also the same


* - ImYourFather - Nov 18, 2015

(Nov 17, 2015 06:14 PM)Rʌv3ɲ Wrote:  So, in my form1 I got my login and I wanna get the username in the first textbox over to my form2 after logging in.

You can make constructor in Form2, and set values from textboxes to properties:
Code
private string login;
private string password

public void Form2(string login, string password){
  this.login = login;
  this.password = password;
}

And calling from Form1:
Code
Form2 mainForm = Form2(textBox1.Text, textBox2.Text);
this.Hide();
mainForm.Show();