Reputation: 21
I have a Form 1 as listed below, im trying to inherit the variable text from it so i can compare is value in an if statement so i can output the file specified for that id number in Form 2...is this possible???
Form 1, where variable is being used:
public void button2_Click(object sender, System.EventArgs e) { timer1.Enabled = true;
string text = textBox1.Text;
Mainform = this;
this.Hide();
}
Form 2 where im trying to use the variable:
if (text == "900456318") {
System.Diagnostics.Process.Start("C:\\Users\\Joshua Banks\\Desktop\\Downtown_atlanta_night");
}
}
Upvotes: 0
Views: 827
Reputation: 2686
If Form1 is calling/creating Form2, you could pass text in the constructor of Form2, thus having Form2 make use of the variable.
You could also have a variable in Form2 with proper get/set methods so you could write:
Form2.SomeVariable = text;
Upvotes: 1