Global array not being accessed correctly
<p>Below is my current code:</p>

<pre><code>    namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public int[] trialArray = new int[10];
        public int trialCounter = -1;

        private void button1_Click(object sender, EventArgs e)
        {
            bool button1Click = true;
            if (button1Click == true) 
            {
                ITIpanel.Visible = true;   

                for (int i = 0; i &lt; trialArray.Length; i++) { trialArray[i] = -1; } // Set default value through array

                int counter = 0;

                Random rnd = new Random();

                while (counter &lt; 10 / 2)
                {  // Red trials, fill half array

                    int index = rnd.Next(0, 10 - 1);

                    if (trialArray[index] == -1) { trialArray[index] = 1; ++counter; } //if unchanged value, change it

                }
                while (counter &lt; 10)
                {
                    int index = rnd.Next(0, 10);

                    if (trialArray[index] == -1) { trialArray[index] = 2; ++counter; }
                }
            }
        }

        private void ITIpanel_Paint(object sender, PaintEventArgs e)
        {
            if (ITIpanel.Visible == true)
            {
                trialCounter += 1; 
                timer1.Enabled = true;
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {

            ITIpanel.Visible = false;
            timer1.Enabled = false; 
            if (trialArray[trialCounter] == 1) { redstimPanel.Visible = true;  }

            else { bluestimPanel.Visible = true;}

            if (trialCounter == 9) { Application.Exit(); } 


        }
        public int counter = 0;
        public event EventHandler Clicked5TimesEvent;
        private void OnClicked5TimesEvent()
        { if (Clicked5TimesEvent != null) { Clicked5TimesEvent(this, EventArgs.Empty); } }

        private void bluestimPanel_MouseDown(object sender, EventArgs e)
        {
            //FR requirement
            counter++; if (counter % 5 == 0) { redstimPanel.Visible = false; ITIpanel.Visible = true; }
        }

        private void redstimPanel_MouseDown(object sender, EventArgs e)
        {
            //FR requirement
            counter++; if (counter % 5 == 0) { redstimPanel.Visible = false; ITIpanel.Visible = true; }
        }


    }
}
</code></pre>

<p>As you can see, I am attempting to make a global array with 10 items. On the button click the 10 items are supposed to be altered such that half contain the value 1 and the other half contain the value 2. </p>

<p>Then, on the timer tick, depending on the value in the <code>trialCounter</code>, which determines the part of the array to be accessed, it should display either the <code>redstimPanel</code> or the <code>bluestimPanel</code>. </p>

<p>Therefore, if the 'trialCounter' is equal to 8, and 8 in the TrialArray is equal 1, the 'redstimPanel' should become Visible. Alternatively, if 8 in the 'TrialArray' is equal to 2, the 'bluestimPanel' should become Visible. </p>

<p>This, however, is not working as I would like it to. Thus, there are clearly some issues with my code. Do you all have any suggestions?</p>
