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 form1 to form3, that is,
Text from FORM2-->FORM1-->FORM3
- Form 1, has 2 buttons , openform2, openform3.
- Form2 has a textbox form2_textbox, & a button send_to_form1_button
- Form3 has a textbox received_from_form1_textbox
Now,
- on clicking button
openform2onform1,Form2opens, - a string is entered in textbox
form2_textboxofForm2, - when button
form2_buttonof this form is clicked, then I wantForm1to receive this string value & stores it in a stringreceivefromform2, - and then displays this string value on to
form3_textboxofForm3.
public partial class Form1 : Form
{
string receivefromForm2a;
public Form1()
{ InitializeComponent(); }
public void Method_Receive_From_Form2(string receivefromForm2)
{
receivefromForm2a = receivefromForm2;
Form3 f3 = new Form3(receivefromForm2a);
}
private void openform3_Click(object sender, EventArgs e)
{
Form3 f3 = new Form3();**----this line gives error:No overload for method Form3 takes 0 arguments**
f3.Show();
}
private void OPENFORM2_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
}
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
string loginname = form2_textbox.Text;
}
//SENDING VALUE OF TEXTBOX ON FORM2 TO FORM1.
private void send_to_form1_button_Click(object sender, EventArgs e)
{
Form1 f1 = new Form1();
f1.Method_Receive_From_Form2(form2_textbox.Text);
}
}
public partial class Form3 : Form
{
public Form3(string receive_from_Form1)
{
InitializeComponent();
received_from_form1_textbox.Text = receive_from_Form1;
}
}
This error occurs because in form2 I have given argument for form1 during object creation.
So what should I do? Is there any other way to do this or how do I remove this error?
When I include the f3.Show() in the method Method_Receive_From_Form2 then there is no error. but this makes the form3 load automatically without any button click. But I want form3 to open by clicking the button on form1. And then the value to be shown in the textbox.