tags:

views:

68

answers:

1

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");

       }

       }
+1  A: 

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;
Robb
so the first way i would just past it through like this?public Form2(text)
JB
Yup just modify your Form2 constructor to take a string.
Robb
having problems modifying my constructor to do such!!
JB
You can just add a new constructor to take the string param to Form2 and use that from Form1. I think this link will help as well: http://www.dreamincode.net/forums/topic/75208-passing-data-between-forms-in-c%23/
Robb