这是我的代码:
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();
}
}
}
然后是另一个类:
namespace Class_Properties {
public partial class Form2 : Form {
public Form2() {
InitializeComponent();
Form1 mainWindow = new Form1();
this.Height = mainWindow.firstHeight;
}
}
}
当我运行时,我键入200
值textbox2
并单击button1
,然后 Visual Studio 会出现以下异常:
我能做些什么来解决这个错误?