[ACCEPTED]-Creating Wizards for Windows Forms in C#-wizard
Lots of ways to do it. Creating a form 20 for each wizard step is possible, but very 19 awkward. And ugly, lots of flickering when 18 the user changes the step. Making each 17 step a UserControl can work, you simply 16 switch them in and out of the form's Controls 15 collection. Or make one of them Visible 14 = true for each step. The UC design tends 13 to get convoluted though, you have to add 12 public properties for each UI item.
The easy 11 and RAD way is to use a TabControl. Works 10 very well in the designer since it allows 9 you to switch tabs at design time and drop 8 controls on each tab. Switching steps is 7 trivial, just change the SelectedIndex property. The 6 only thing non-trivial is to hide the tabs 5 at runtime. Still easy to do by processing 4 a Windows message. Add a new class to your 3 form and paste the code shown below. Compile. Drop 2 the new control from the top of the toolbox 1 onto your form.
using System;
using System.Windows.Forms;
class WizardPages : TabControl {
protected override void WndProc(ref Message m) {
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
}
class WizardPages : TabControl
{
protected override void WndProc(ref Message m)
{
// Hide tabs by trapping the TCM_ADJUSTRECT message
if (m.Msg == 0x1328 && !DesignMode) m.Result = (IntPtr)1;
else base.WndProc(ref m);
}
protected override void OnKeyDown(KeyEventArgs ke)
{
// Block Ctrl+Tab and Ctrl+Shift+Tab hotkeys
if (ke.Control && ke.KeyCode == Keys.Tab)
return;
base.OnKeyDown(ke);
}
}
0
You need to create your own to meet your 6 own preferences. A tip will be for you to 5 create a base form named like "frmWizard" then 4 all your wizard windows will inherit from 3 it. You should put common objects or wizard 2 objects on the base class and modify \ override 1 them on the derived class if needed.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.