How do you get a value from one form in another form? I've tried the following but it doesn't work.
Form1:
public TextBox TXT()
{
get{return txtbox1;}
}
Form2:
public Form1 frm;
txtbox2.Text=frm.TXT.Text;
How do you get a value from one form in another form? I've tried the following but it doesn't work.
Form1:
public TextBox TXT()
{
get{return txtbox1;}
}
Form2:
public Form1 frm;
txtbox2.Text=frm.TXT.Text;
Declare your Form1's txtbox1 Modifier as public . And in Form2 Declare the following:
System.Windows.Forms.Form f = System.Windows.Forms.Application.OpenForms["Form1"];
Then :
txtbox2.Text = ((Form1)f).txtbox1.Text;
Try the following.
Form1.cs
private Form2 secondForm;
private void GetSecondFormTextBox()
{
textBox1.Text = secondForm.TextBox1.Text;
}
Form2.cs
public TextBox TextBox1
{
get
{
return textBox1;
}
}
Form2
public String txtval { get; set; }
txtBox2.Text = txtval;
Form1
Form2 frm2 = new Form2();
frm2.txtval = txtBox1.Text;
Try to assign the Form1.TextBox1.Tex
t into a Public Shared
variable and access the variable into the Form2.TextBox1.Text