Caleb Dunn

Caleb Dunn

  • NA
  • 59
  • 29k

C# back and forward buttons? Why dont they work?

Dec 29 2011 9:12 PM
Ive spent a lot of time trying to figure out why these dont work right. Can some one take a look at it and maybe fix some of my mistakes? The panels arent switching still.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();

        }

        private void Form4_Load(object sender, EventArgs e)
        {

        }

        private void fusionButton2_Click(object sender, EventArgs e)
        {
            //Minimizes the program

            this.WindowState = FormWindowState.Minimized;
        }

        private void fusionButton1_Click(object sender, EventArgs e)
        {
            //Maximizes and sets Normal
            if (this.WindowState == FormWindowState.Normal)
            {

                this.WindowState = FormWindowState.Maximized;

            }

            else if (this.WindowState == FormWindowState.Maximized)
            {

                this.WindowState = FormWindowState.Normal;

            }
        }

        private void fusionButton3_Click(object sender, EventArgs e)
        {
            //******************************************************/
            //This makes it so yes CLOSES the program and NO keeps              */
            //stays open                                                                                */
            //******************************************************/

            DialogResult result;
            result = MessageBox.Show("Do you want to close this program?", "Question", MessageBoxButtons.YesNo);
            if (result == DialogResult.Yes)
            {
                Close();//Closes the program
            }
            if (result == DialogResult.No)
            {
                //Leave empty to do nothing
            }


        }

  int counter = 0;
  int maximum = 2; //Maximium = total panels started from 0, 1, 2
  //private void fusionButton5_Click(object sender, EventArgs e)
  //{
  //counter++;//the ++ after a integer raises the value by 1
// if (counter > 0)//checks to see if counter value is greater than 1
// {
// fusionButton5.Enabled = true;
// }
// if (counter == maximum) //checks to see if counter is equal to that of maximum
// {
// fusionButton4.Enabled = false;
// }
//  }

  private void fusionButton5_Click(object sender, EventArgs e)
  {

      int original = counter;

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

      if (counter > maximum) counter = maximum;

      fusionButton4.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
      {

          fusionButton5.Enabled = false; // disable forward button

      }

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

  }

  private void fusionButton4_Click(object sender, EventArgs e)
  {

      int original = counter;

      counter--;

      if (counter < 0) counter = 0;

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

      if (counter == 0)
      {

          fusionButton4.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;
      }

  }
  private void fusionTheme1_Click(object sender, EventArgs e)
  {

  }

  }
}



Answers (8)