[Solved] Creating a form that updates when ‘Next’ button is clicked. (c#) [closed]


In your form design, make the base layer a TabControl and then create tabs for each “page”. Ensure that your button is not on a tab page, but on the base form. Then, handle the button click, switching tabs to a new “page” each time. Keep track of the current page using a member variable of type int.

Since you’ve not provided code, I’ll make some assumptions for example’s sake. The TabControl is named “tabControl”, and it has n number of pages named “tabPage_Page0” through “tabPage_Pagen”. The Next button’s click handler would go something like this:

private void NextButton_Click (Object sender, EventArgs e)
{
    switch (_currentIndex)
    {
        case 0:
            tabControl.SelectTab(tabPage_Page1);
            break;
        case 1:
            tabControl.SelectTab(tabPage_Page2);
            break;
        case n:  //whatever that last number really is
            tabControl.SelectTab(tabPage_Page0);  //wrap back to the first page?  or exit?
            _currentIndex = 0;
            return;
    }

    _currentIndex++;
}

We use something similar quite a bit. However, we have gone further and created a class inheriting from TabControl that provides a HideTabs member that we use to override DisplayRectangle() and force the tabs invisible. Makes a nice clean presentation.

1

solved Creating a form that updates when ‘Next’ button is clicked. (c#) [closed]