我有一个下面列出的表单1,我试图从它继承变量文本,所以我可以比较if语句中的值,所以我可以输出为表单2中的id号指定的文件...这是可能???
表单1,其中使用了变量:
public void button2_Click(object sender,System.EventArgs e) { timer1.Enabled = true;
string text = textBox1.Text;
Mainform = this;
this.Hide();
}
表单2我试图使用变量:
if(text ==“900456318”) {
System.Diagnostics.Process.Start("C:\\Users\\Joshua Banks\\Desktop\\Downtown_atlanta_night");
}
}
答案 0 :(得分:1)
如果Form1正在调用/创建Form2,您可以在Form2的构造函数中传递文本,从而让Form2使用该变量。
你也可以在Form2中使用正确的get / set方法获得一个变量,这样你就可以写:
Form2.SomeVariable = text;