I want to set values in array from textBoxes in Form1 and send it as Global variable to Form2, but the array does not pass through forms.
class GlobalVariables
{
private string[] array = new string[3];
public string[] Array
{
get { return array; }
set { array = value; }
}
}
If i click button1_Click in Form1, values from textBoxes should be set in array and sent to constructor in class GlobalVariables.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
GlobalVariables G = new GlobalVariables();
string[] array = new string[3];
array[0] = textBox1.Text;
array[1] = textBox2.Text;
array[2] = textBox3.Text;
G.Array = array;
Form2 f2 = new Form2();
f2.Show();
}
}
If i click button1_Click in Form2, values from constructor Array should be sent to array and then to labels.
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
GlobalVariables G = new GlobalVariables();
string[] array= G.Array;
label1.Text = array[0];
label2.Text = array[1];
label3.Text = array[2];
}
}