How can I get the value's of variables from a separate form?
You can expose them through properties.
For example, if form Form2 has a variable named _Count
of type int
, you can create a property like this:
public int Count
{
get { return _Count; }
}
Then you can access that property on Form2 instances.
As long as the other form is running and the variable is accessible (public) that you just need to pass the reference to the form.
You can also pass in your values in an overloaded constructor of your instantiated form.
if you want to read the values of few variables you can go with the solution provided by CesarGon.
Its simple you can get the values of properties like Form2.Count and so on...while your form is not disposed.
You can create a method returning Hashtable which will contain the values you want to return. for example
public Hashtable GetData()
{
Hashtable ht = new Hashtable();
ht.add('count',textBox1.Text);
return ht;
}
If you want to pass values of one form to another form you can pass them from the constructor of second form.
You just need to add the following code in the other form if you want to get a specific value of a variable for instance a textbox... Note that the variable text is declared to who will receive the value and that it is static.
public Form2(string text)
{
InitializeComponent();
text = textBox.text;
}