I have read through some of the posts on this site relating to this error but I still can\'t work out how to do this - I\'m quite new to C#.
I am trying to pass mult
You are not suppling the second value. It takes 2 parameters.
Form3 a = new Form3(firstNameTxtBox.Text,lastNametextBox.Text);
I think you mean this
Form3 a = new Form3(firstNameTxtBox.Text, lastNametextBox.Text);
a.Show();
Compiler says Form3
doeesn't have a contructor with 1 argument. It is true.
public Form3(string a, string b)
This takes two parameters. So you'll have to pass two arguments.
When you say new Form3(firstNameTxtBox.Text);
you're passing argument to parameter string a
compiler says you have to pass string b
also.
As a side note: Don't name variables and types names like a
, b
, Form1
etc. Purpose of the variable should be exposed by name itself.
Make firstNameLbl
and lastNameLbl
public
Then initiate the new form like this:
var f3= new Form3();
f3.firstNameLbl.Text = firstNameTxtBox.Text;
f3.lastNameLbl.Text = lastNametextBox.Text;
f3.Show();
Here
Form3 a = new Form3(firstNameTxtBox.Text);
you are calling the Form3
constructor with one argument.
As the error explains, Form3
does not contain a constructor that takes a single argument. This is why when you remove the second argument from the constructor the error goes away.
You have two options:
1) Remove the second constructor argument.
public Form3(string a)
{
InitializeComponent();
firstNameLbl.Text = a;
}
2) Add the second argument to all the places where you call the Form3
constructor.
If you need the second constructor argument I suggest option 2.
For example:
Form3 a = new Form3(firstNameTxtBox.Text, lastNametextBox.Text);
Your final Form1 code would look something like:
public Form1()
{
InitializeComponent();
}
private void nextBtn_Click(object sender, EventArgs e)
{
Form3 a = new Form3(firstNameTxtBox.Text, lastNametextBox.Text);
a.Show();
this.Hide();
}
as you said if you have N forms then the date Exchange may be , i think ,More than saving it in a file u can use static class with get/set something like
Lets have a new Class GlobalClass
public static class GlobalClass
{
public static string firstNameTxtBox
{ set; get; }
public static string SecondNameTxtBox
{ set; get; }
}
and u can set from any form (Namespace should b be noted)
@Form1
GlobalClass.firstNameTxtBox="This is From 1stForm";
@Form2
GlobalClass.SecondNameTxtBox="This is From Second Form";