Introduction
This article will explain how to make wizard like application by using Windows.Forms.TabControl .NET control.
I will provide only necessary inline code, because I will talk more about architecture.
(Please forgive my english)
Background
Recently I read article A simple Wizard control for .Net 2.0 with full designer support By Manish Ranjan Kumar. He developed very useful component for wizards where the app logic is like Start -> Next -> .. -> Finish. But what to do when we need more personalized behavior?
Description
I decided to use TabControl control because of its pages and therefore good design time support when creating steps in our wizard. So it is easy - each page is one step in wizard process. Wizards usually have at least two buttons: Next and Back. We can put it outside of TabControl to make them common, or inside in each page in case of count of buttons or their labels vary by page (step).
The problem is only how to hide tab's title and do not allow to change tabs by user will. Both is easy. We can hide tabpages putting Panel control (or something else) over this buttons. This also disables switching tabs by mouse. To disable switching them by keys, we simply add following code:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (ActiveControl is TabControl)
{
if (System.Convert.ToBoolean(keyData & Keys.Tab | Keys.Control))
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}
which override form key handler in case of TabControl. And it is finished. We can make application logic as complicated as we need :)
Some usefull tips
I created many wizards using this structure, some were easy and some more difficult, and here I some tips I can remember while I was developing them:
- Adjust the height of "overlapping panel" programmatically, so you can switch tabs in design time by mouse...
- If the background of each tab is same, set it programmatically, because when set in designer, the bitmap will appear in your resources many times.
(I was doing it by setting bg on one tab, then copy generated key with value to new resource file, and then set it on Form_Load for each tab, see code below.
ResourceManager resManager = new ResourceManager("namespace.filename", this.GetType().Assembly);
Bitmap imgMain = (Bitmap)resManager.GetObject("resourcekey");
resManager.ReleaseAllResources();
foreach (TabPage tab in tabControl1.TabPages) tab.BackgroundImage = imgMain;
History
No updates
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.