This is my code:
namespace Class_Properties {
public partial class Form1 : Form {
private string firstHeight1 = "";
public int firstHeight {
get {
return Convert.ToInt32( firstHeight1 );
}
}
public Form1() {
InitializeComponent();
}
private void button1_Click( object sender, EventArgs e ) {
firstHeight1 = textBox2.Text;
Form2 secondForm = new Form2();
secondForm.Show();
}
}
}
and then the other class:
namespace Class_Properties {
public partial class Form2 : Form {
public Form2() {
InitializeComponent();
Form1 mainWindow = new Form1();
this.Height = mainWindow.firstHeight;
}
}
}
When I run, I type 200 as value for textbox2 and click button1, then Visual Studio says the following exception:

What could I do to solve this error?
This is the failure:
No matter what you did on the other
Form1, it won’t show up in this one because it’s a new instance sofirstHeight == string.Emptyand will fail the parse.You’ll have to send the existing Form1 to Form2:
Though admittedly, it would be better to send only what you need: