I've recently come across 3 projects that needed 'Wizard-like' functionality. What I mean by this is that there was a need to guide the user through a process of either data entry or questions to get to an end result. This is pretty common functionality but there are numerous ways to implement, and the effectiveness of a certain implementations is sometimes questionable. I'd like to offer a walkthrough on one of these approaches I've been using recently to at least offer a jump off point to someone that could be solving the same issue.
Prerequisites: (What I'm using and assuming you know…)
In a new Windows Forms Application, on the Form, add the UltraTabControl from the Toolbox. Set the 'Style' property to "Wizard". This removes the classic "tab" look from the tab control. We'll be able to use button navigation now that is typically associated with a wizard. Following widely accepted design, I place three buttons the "Shared controls page" of the UltraTabControl, "Cancel" on the bottom-left, "Back" and "Next"/"Finish" on the bottom-right.
Since the Back button won't be needed on the first tab/step of the wizard I set the Visible property to false. Next I implement the events for the Back and Next buttons.
private
void cmdNext_Click(object sender, EventArgs e)
{
if (tbcWizard.SelectedTab.Index == tbcWizard.Tabs.Count - 1)
{
// Save/Final button was clicked (last step)
return; // May or may not be needed, depends on above
}
// Optional, implement if you need to do validation on a step or process
// information before reaching the end of the wizard
switch (tbcWizard.SelectedTab.Index)
{
case 0: // Step 1
break;
case 1: // Step 2
break;
case 2: // Step 3...
break;
default:
break;
}
if (tbcWizard.SelectedTab.Index < tbcWizard.Tabs.Count - 1)
{
// Move to the next step
tbcWizard.SelectedTab = tbcWizard.Tabs[tbcWizard.SelectedTab.Index + 1];
// Optional, in this case there is a label on the Shared page that is
// updated with the current tab/steps text...helpful for the user
lblStepHeader.Text = tbcWizard.SelectedTab.Text;
// Check if the tab is the last one, change "Next" text to "Finish"
if (tbcWizard.SelectedTab.Index == tbcWizard.Tabs.Count - 1)
cmdNext.Text = "Finish";
else
cmdNext.Text = "Next";
// Check if the tab is the first one, disable the "Back" button
if (tbcWizard.SelectedTab.Index == 0)
cmdBack.Visible = false;
else
cmdBack.Visible = true;
}
}
private
void cmdBack_Click(object sender, EventArgs e)
{
if (tbcWizard.SelectedTab.Index == 0)
return;
// Move to the previous step
tbcWizard.SelectedTab = tbcWizard.Tabs[tbcWizard.SelectedTab.Index - 1];
// Optional, in this case there is a label on the Shared page that is
// updated with the current tab/steps text...helpful for the user
lblStepHeader.Text = tbcWizard.SelectedTab.Text;
// Check if the tab is the last one, change "Next" text to "Finish"
if (tbcWizard.SelectedTab.Index == tbcWizard.Tabs.Count - 1)
cmdNext.Text = "Finish";
else
cmdNext.Text = "Next";
// Check if the tab is the first one, disable the "Back" button
if (tbcWizard.SelectedTab.Index == 0)
cmdBack.Visible = false;
else
cmdBack.Visible = true;
}
The inline comments do a decent job of explaining what this simple chunk of code is doing. I'd be more than happy to provide a more robust and functioning solution if you use Infragistics controls and are interested. Please leave a comment and I'll be happy to send it along. So while very simple, this approach has been effective and efficient in all my latest needs to implement a wizard. Enjoy!