private void hideStateDFA1()
 {
     DFA2simState0.Hide();
     DFA2simState1.Hide();
     DFA2simState2.Hide();
     DFA2simState3.Hide();
     DFA2simState4.Hide();
     DFA2simState5.Hide();
     DFA2simState6.Hide();
     DFA2simStateEndLoop.Hide();
 }
        private void onNext(object sender, EventArgs e)
        {
            sim = stringSimulation.ToCharArray(); //sim = stringSimulation.ToCharArray();
            switch (lblRegex.Text)
            {
                #region REGEX1
            case "Regular Expression:  (aa+bb)(a+b)* (a+b+ab+ba) (a+b+ab+ba)* (aa+bab)* (a+b+aa) (a+b+bb)*":
                if (forCTR <= stringSimulation.Length - 1)
                {
                    if (currentState == 0)
                    {
                        DFA1simState0.Show();
                        //StatusBar.Text = "The string enters start state!";
                        currentState++;
                    }

                    else if (currentState == 1)
                    {
                        if (sim[forCTR] == 'a')
                        {
                            DFA1simState0.Hide();
                            DFA1simState1a.Show();
                            lblInputChar.Text = Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "Since input is a, the string enters state 1a";
                            forCTR++;
                            currentState++;
                        }

                        else if (sim[forCTR] == 'b')
                        {
                            DFA1simState0.Hide();
                            DFA1simState1b.Show();
                            lblInputChar.Text = Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "Since input is b, the string enters state 1b";
                            forCTR++;
                            currentState++;
                        }

                        else
                        {
                            //start state only
                            lblInputChar.Text = "INVALID INPUT";
                            //StatusBar.Text = "The string is stuck in start state, and is therefore invalid";
                            btnNext.Enabled = false;
                        }
                    }

                    else if (currentState == 2)
                    {
                        if (sim[forCTR - 1] == 'a' && sim[forCTR] == 'a')
                        {
                            DFA1simState1a.Hide();
                            DFA1simState2.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 1a, the input is a, therefore the string enters state 2";
                            forCTR++;
                            currentState++;
                        }

                        else if (sim[forCTR - 1] == 'b' && sim[forCTR] == 'b')
                        {
                            DFA1simState1b.Hide();
                            DFA1simState2.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 1b, the input is b, therefore the string enters state 2";
                            forCTR++;
                            currentState++;
                        }

                        else if (sim[forCTR - 1] == 'a' && sim[forCTR] == 'b')
                        {
                            DFA1simState1a.Hide();
                            DFA1simState6.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 1a, the input is b, the string enters a trap state, and therefore is considered invalid for the DFA";
                            lblInputChar.Text = "INVALID INPUT";
                            forCTR++;
                            currentState++;
                            btnNext.Enabled = false;
                        }

                        else if (sim[forCTR - 1] == 'b' && sim[forCTR] == 'a')
                        {
                            DFA1simState1b.Hide();
                            DFA1simState6.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 1b, the input is a, the string enters a trap state, and therefore is considered invalid for the DFA";
                            lblInputChar.Text = "INVALID INPUT";
                            forCTR++;
                            currentState++;
                            btnNext.Enabled = false;
                        }

                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            //StatusBar.Text = "The string does not reach the end state, and is therefore invalid";
                            btnNext.Enabled = false;
                        }
                    }

                    else if (currentState == 3)
                    {
                        if (sim[forCTR] == 'a' || sim[forCTR] == 'b')
                        {
                            DFA1simState2.Hide();
                            DFA1simState3.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState++;
                        }

                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            //StatusBar.Text = "The string does not reach the end state, and is therefore invalid";
                            btnNext.Enabled = false;
                        }
                    }

                    else if (currentState == 4)
                    {
                        if (sim[forCTR] == 'a' || sim[forCTR] == 'b')
                        {
                            DFA1simState3.Hide();
                            DFA1simState4.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 3, the input is " + sim[forCTR] + ", therefore the string enters state 4";
                            forCTR++;
                            currentState++;
                        }

                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            //StatusBar.Text = "The string does not reach the end state, and is therefore invalid";
                            btnNext.Enabled = false;
                        }
                    }

                    else if (currentState > 4)
                    {
                        if (sim[forCTR] == 'a' || sim[forCTR] == 'b')
                        {
                            DFA1simState4.Hide();
                            DFA1simStateEndLoop.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            //StatusBar.Text = "From state 4, the input is " + sim[forCTR] + ", therefore the string stays in state 4";
                            forCTR++;
                            currentState++;
                        }

                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            //StatusBar.Text = "Input is neither a or b so the string doesn't go to any state, and is therefore invalid";
                            btnNext.Enabled = false;
                        }
                    }
                }

                else
                {
                    if (currentState > 4)
                    {
                        lblInputChar.Text = "VALID INPUT";
                        //StatusBar.Text = "The string ends in the end state, and is therefore valid!";
                        btnNext.Enabled = false;
                    }

                    else if (currentState <= 4)
                    {
                        lblInputChar.Text = "INVALID INPUT";
                        // StatusBar.Text = "The string does not end in the end state, and is therefore invalid!";
                        btnNext.Enabled = false;
                    }
                    currentState++;
                }
                break;
                #endregion

                #region REGEX2
            case "Regular Expression: ((101+111+101) + (1+0+11)*) (1+0+01)* (111+000+101) (1+0)*":
                if (forCTR <= stringSimulation.Length - 1)
                {
                    if (currentState == 0)
                    {
                        DFA2simState0.Show();
                        currentState = 1;
                    }
                    else if (currentState == 1)    //starting state
                    {
                        if (sim[forCTR] == '1')
                        {
                            DFA2simState0.Hide();
                            DFA2simState1.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 2;
                        }

                        else if (sim[forCTR] == '0')
                        {
                            DFA2simState0.Hide();
                            DFA2simState1.Hide();
                            DFA2simState2.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 2;
                        }

                        else
                        {
                            //start state only
                            lblInputChar.Text = "INVALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                    else if (currentState == 2)
                    {
                        if (sim[forCTR - 1] == '1' && sim[forCTR] == '1')
                        {
                            DFA2simState1.Hide();
                            DFA2simState3.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 3;
                        }

                        else if (sim[forCTR - 1] == '1' && sim[forCTR] == '0')
                        {
                            DFA2simState1.Hide();
                            DFA2simState4.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 4;
                        }
                        else if (sim[forCTR - 1] == '0' && sim[forCTR] == '0')
                        {
                            DFA2simState2.Hide();
                            DFA2simState5.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 5;
                        }
                        else if (sim[forCTR - 1] == '0' && sim[forCTR] == '1')
                        {
                            DFA2simState2.Hide();
                            DFA2simState1.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 2;
                        }
                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                    else if (currentState == 3)
                    {
                        if (sim[forCTR] == '1')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState6.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 6;
                        }
                        else if (sim[forCTR] == '0')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 4;
                        }
                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                    else if (currentState == 4)
                    {
                        if (sim[forCTR] == '1')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState6.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 6;
                        }
                        else if (sim[forCTR] == '0')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState5.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 5;
                        }
                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                    else if (currentState == 5)
                    {
                        if (sim[forCTR] == '1')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState5.Hide();
                            DFA2simState1.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 2;
                        }
                        else if (sim[forCTR] == '0')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState5.Hide();
                            DFA2simState6.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState = 6;
                        }
                        else
                        {
                            //STAYS WHEREVER IT IS
                            lblInputChar.Text = "INVALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                    else if (currentState >= 6)
                    {
                        if (sim[forCTR] == '1' || sim[forCTR] == '0')
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState5.Hide();
                            DFA2simState6.Hide();
                            DFA2simStateEndLoop.Show();
                            lblInputChar.Text += Convert.ToString(sim[forCTR]);
                            forCTR++;
                            currentState++;
                        }
                        else
                        {
                            DFA2simState1.Hide();
                            DFA2simState2.Hide();
                            DFA2simState3.Hide();
                            DFA2simState4.Hide();
                            DFA2simState5.Hide();
                            DFA2simState6.Show();
                            lblInputChar.Text = "VALID INPUT";
                            btnNext.Enabled   = false;
                        }
                    }
                }
                else
                {
                    if (currentState >= 6)
                    {
                        lblInputChar.Text = "VALID INPUT";
                        btnNext.Enabled   = false;
                    }

                    else if (currentState < 6)
                    {
                        lblInputChar.Text = "INVALID INPUT";
                        btnNext.Enabled   = false;
                    }
                    currentState++;
                }

                break;
            }
        }