I have a windows application which has 3 forms : Form1,2,3. I want to send text of a textbox from form2
to form1
and then that same text from for
I would recommend a change from using constructors to using properties. This will keep things properly 'contained' and it's pretty simple.
EX:
public partial class Form3 : Form
{
public String form1Text {get; set;}
public Form3()
{
InitializeComponent();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
string loginname = form2_textbox.Text;
}
public String form2Text {get; set;}
private void send_to_form1_button_Click(object sender, EventArgs e)
{
form2Text = form2_textbox.Text;
this.DialogResult = DialogResult.Ok;
this.Close();
}
}
Then in form 1:
public partial class Form1 : Form
{
string receivefromForm2a;
public Form1()
{ InitializeComponent(); }
private void openform3_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();
f3.form1Text = receivefromForm2a;
f3.Show();
}
private void OPENFORM2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
if(f2.ShowDialog() == DialogResult.Ok)
{
receivefromForm2a = f2.form2Text; //New Property on Form2.
}
}
}