Saturday, June 23, 2012

Creating Wizard using C# Form (Tab Control)

In one of the previous posting there is a Wizard implementation which used console application and multiple forms. But sometimes requirements are so that implementation needed to some sort of Wizard type but not with all pomp and show, even time constraint makes it hard to achieve an evolving application.

Creating Wizard using tab control is the other to do that, it is simple way to do that. It is a single form implementation with Wizard flavor. This implementation has following basic tweaks to achieve, rest of the implementations and functionality are user specific:

  1. Inherit TabControl and hide tabs by supressing TCM_ADJUSTRECT
  2. Then replace the instance of TabControl Class object initialisation with your class (in my case I names WizardTabControl). Do this replacement once you have completed the screen design and feature is complete.
  3. Set the dock property to Fill for TabPage

Implementation:
Following changes in Form.Designer.cs is the only thing needed. Add Following code at the end to inherit the TabControl class.
namespace System.Windows.Forms
{
    public class WizardTabControl : TabControl
    {
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == 0x1328 && !DesignMode) // Hide tabs by trapping the TCM_ADJUSTRECT message
                m.Result = IntPtr.Zero;
            else
                base.WndProc(ref m);
        }
    }
}

Changes in Form class, replace the TabControl reference with WizardTabControl
private System.Windows.Forms.WizardTabControl tabControl1;
private void InitializeComponent()
{
    this.tabControl1 = new System.Windows.Forms.WizardTabControl();
}

4 comments:

  1. Thanks for very precise information.
    I appretiate the effort you took for this blog !!

    Rak

    ReplyDelete
  2. Very Helpful! Thanks.

    ReplyDelete
  3. what effort!? this is copy & paste from the web

    ReplyDelete