how to transfer text from a textbox of one form to another forms textbox?
javed khan
Consider Form1 contains a textbox named textBox1 and a button named button1Form2 contains no controls .
When user clicks on button1 textBox1's text will be transfered from form1 to form2 by writing this code.
Code for Form1 :
{
f2.Controls.Add(text);
text.Text = textBox1.Text;
f2.Show();
}
Consider Form1 contains a textbox named textbox1 and a button named button1Form2 contains a textbox named textbox1. When user clicks on button1 text will be transfered from form1 to form2 by writing this code.
We are passing the reference of form1 to form2.
private void button1_Click() {Form2 obj=new Form2(this);obj.show();}
Code for Form2:
Form1 obj;public Form1(Form1 obj1){ obj=obj1; InitializeComponent();}
private void Form2_Load(object sender, EventArgs e){textbox1.Text=obj.textbox1.Text;}