这是我的代码:奇怪的错误(输入的字符串格式不正确。)
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中说,以下情况除外:
我能做些什么来解决这个错误?
这个工作...所以我必须明白,我可以通过将Form1作为参数传递给Form2()... ... – Victor
@维克多:我真的建议只发送你需要的Form2而不是Form1本身。如果可以的话,耦合是一种避免的习惯,并且基于你的例子,Form2真的不需要了解Form1。 –
好的。非常感谢你! :) – Victor