Caleb Dunn

Caleb Dunn

  • NA
  • 59
  • 28.9k

Can any1 finish this 7 panel back and forth code for me? ( C#)

Dec 31 2011 7:32 AM
I hate to ask this question, but I seriously need help. There are already 3 panels in the code that the buttons switch through. What I need is for it to switch through 7 different panels. The reason why im asking help on this is because ive been up over 48 hours working on a project and I need some sleep and its due by next monday...Also I have a lot of family stuff to do this weekend so ill only get 1-2 days to finish the rest including animations so if anyone can please do this for me it would make my life a lot easier.

        private void Form4_Load(object sender, EventArgs e)
        {
            btn1.Enabled = false;
            PanelSwitcher();
            btn1.Click += btn1_Click; // back button
            btn2.Click += btn2_Click; // forward button
        }

        int counter = 0;
        int maximum = 2; //Maximium = total panels started from 0, 1, 2

        private void btn2_Click(object sender, EventArgs e)
        {

            int original = counter;

            counter++; //the ++ after a integer raises the value by 1

            if (counter > maximum) counter = maximum;

            btn1.Enabled = true; // counter must be at least 1, so enable back button

            if (counter == maximum) //checks to see if counter is equal to that of maximum
            {

                btn2.Enabled = false; // disable forward button

            }

            if (counter != original) PanelSwitcher(); // switch panel if counter has changed

        }

        private void btn1_Click(object sender, EventArgs e)
        {

            int original = counter;

            counter--;

            if (counter < 0) counter = 0;

            btn2.Enabled = true; // counter must be less than maximum, so enable forward button

            if (counter == 0)
            {

                btn1.Enabled = false; // disable back button

            }

            if (counter != original) PanelSwitcher(); // switch panel if counter has changed

        }

        private void PanelSwitcher() // no longer a timer Tick handler
        {
            switch (counter)
            {
                case 0:
                    panel1.Visible = true;
                    panel2.Visible = false;
                    panel3.Visible = false;
                    break;
                case 1:
                    panel1.Visible = false;
                    panel2.Visible = true;
                    panel3.Visible = false;
                    break;
                case 2:
                    panel1.Visible = false;
                    panel2.Visible = false;
                    panel3.Visible = true;
                    break;
                }
        }
    }
}

Answers (16)