0

I created a form with multiple panels that show or hide based on pressing various "Next" or "Previous" buttons. This works with all panels except for panelDuelDegree and panelDoubleMajor. The next button properly hides the panel and shows the desired panel. However if I press the previous button on either panel the panelPage1 shows but the DoubleMajor or DuelDegree panel does not hide. Neither panel is a child to panelPage1.

How do I get panelDuelDegree and panelDoubleMajor to hide when I press the "Previous" button?

public partial class CreateNewGradAppForm : Form
{
    //FOR TESTING PURPOSES
    bool duelDegree = true;
    bool doubleMajor = false;

    public CreateNewGradAppForm()
    {
        InitializeComponent();
    }

    private void CreateNewGradAppForm_Load(object sender, EventArgs e)
    {

    }

    private void NextButton_Click(object sender, EventArgs e)
    {
        if (duelDegree)
        {
            panelPage1.Hide();
            panelDuelDegree.Show();
            panelPage1.Enabled = false;
            panelDuelDegree.Enabled = true;
        }
        else if (doubleMajor)
        {
            panelPage1.Hide();
            panelDoubleMajor.Show();
            panelPage1.Enabled = false;
            panelDoubleMajor.Enabled = true;
        }
        else
        {
            panelPage1.Hide();
            panelPage2.Show();
            panelPage1.Enabled = false;
            panelPage2.Enabled = true;
        }

    }
    private void DuelDegreePreviousButton_Click(object sender, EventArgs e)
    {
        panelDuelDegree.Hide();
        panelPage1.Show();
        panelDuelDegree.Enabled = false;
        panelPage1.Enabled = true;
    }

    private void DoubleMajorPreviousButton_Click(object sender, EventArgs e)
    {
        panelDoubleMajor.Hide();
        panelPage1.Show();
        panelDoubleMajor.Enabled = false;
        panelPage1.Enabled = true;
    }
    private void DuelDegreeNextButton_Click(object sender, EventArgs e)
    {
        panelDuelDegree.Hide();
        panelPage2.Show();
        panelDuelDegree.Enabled = false;
        panelPage2.Enabled = true;
    }

    private void DoubleMajorNextButton_Click(object sender, EventArgs e)
    {
        panelDoubleMajor.Hide();
        panelPage2.Show();
        panelDoubleMajor.Enabled = false;
        panelPage2.Enabled = true;
    }
John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • It would probably help if you change the *duelDegree* and *doubleMajor* variables in your code. A much simpler way to do this is by using a [TabControl](http://stackoverflow.com/a/2342320/17034) instead. – Hans Passant Apr 13 '15 at 18:37
  • There are better ways to implement a "wizard". You're reinventing the wheel, here. With that in mind, though... Why set the `Enabled` property if you're hiding the panel. I'd recommend removing that code, since it's essentially redundant. Lastly, the code that you posted does not appear to be all of the code that we would need to see. I'd suggest making a simple test project that includes only the controls and code that you need to reproduce the problem. Usually doing that will show you your problem. If it does not, then it provides an easy way for SO users to recreate your bug & help. – DeadZone Apr 13 '15 at 18:40
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders Apr 13 '15 at 18:58
  • Is this a winforms application? – John Saunders Apr 13 '15 at 18:58

2 Answers2

0

Why don't you just have a list to store all these panels in and just iterate through the list based on a known index of which panel is currently showing then +1 or -1 the index based on which button is clicked?

Shar1er80
  • 9,001
  • 2
  • 20
  • 29
0

try panelPage1.visible = true and panelPage1.visible = false. That should show and hide the panel.

Gus
  • 31
  • 5