Create wizard like window application C#


Hi today we will see how to create wizard like window application in .NET 2.0.

1) Create a new window application.
2) Add three forms in it. I have named the form as FirstStep, SecondStep and ThirdStep.
3) In FirstStep add two button – Next and Cancel
4) In SecondStep add three button- Previous, Next and Cancel
5) In ThirdStep add two button- Previous and Cancel
6) Than add a new class file – name it WizardData.cs
7) Add following code to it

// this wizardData class will have a enumeration and a property to display the appropriate form
public class WizardData
{
public enum wizardForms
{
FirstStep =1, SecondStep=2, ThirdStep=3,Cancel =99
}
private wizardForms formToShow;
public wizardForms FormToShow
{
get
{
return formToShow;
}
set
{
formToShow=value;
}
}
}

8. Then go to program.cs and modify it in the following manner

[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyInitialization();

//Replace Application.Run(…. ) with MyInitialization() – custom function
}

9) The code for MyInitialization() goes like this

// Create instances of all the forms to be displayed
private static void MyInitialization()
{
WizardData wData = new WizardData();
wData.FormToShow = WizardData.wizardForms.FirstStep;
Form step1 = new FirstStep(wData);
Form step2 = new SecondStep(wData);
Form step3 = new ThirdStep(wData);
while (wData.FormToShow != WizardData.wizardForms.Cancel)
{
switch (wData.FormToShow)
{
case WizardData.wizardForms.FirstStep:
{
step1.ShowDialog();
break;
}
case WizardData.wizardForms.SecondStep:
{
step2.ShowDialog();
break;
}
case WizardData.wizardForms.ThirdStep:
{
step3.ShowDialog();
break;
}
}
}
10) Now go to your FirstStep Form. Replace the constructor with this

public FirstStep(WizardData wd)
{
this.wData = wd;
InitializeComponent();
}

11) In the cancel button and next button click event handler write the following code

private void btnNext_Click(object sender, EventArgs e)
{
// to show the SecondStep form
wData.FormToShow = WizardData.wizardForms.SecondStep;
this.Close();
}
private void btnCancel_Click(object sender, EventArgs e)
{
wData.FormToShow = WizardData.wizardForms.Cancel;
this.Close();
}

12) Repeat the same step 11 for SecondStep and ThirdStep form.
for previous button click event handler add the following code
private void btnPrevious_Click(object sender, EventArgs e)
{
// replace the wizardForm.(…) with appropriate form to be displayed
wData.FormToShow = WizardData.wizardForms.FirstStep;
this.Close();
}


That’s it

Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

20 thoughts on “Create wizard like window application C#”

  1. Works fine – and nice how easy you kept it!
    Only flicker in the taskbar and in between changing the forms is not really desireable

    Thanks though

    Like

  2. Works like a charm! Your instructions are almost complete but I would like to add the following:

    Add following to each form:

    private WizardData wData;

    Like

  3. Really Works Fine.
    But flickering is the major issue. Even DoubleBuffering can’t solve the flickering issue. I think it should be a single form displaying the controls based on the Previous & Next button clicks.

    Like

    1. To eliminate the flickering you can try using panels. Using the methods show() and hide() for those panels with the next and previous buttons. The result is pretty nice!

      Like

  4. I think that a single form solution with a user control for each step would be more elegant since that would eliminate the taskbar flickering someone mentioned earlier.

    Like

  5. My problem is that I receiving two err:
    No overload for method ‘SecondStep’ takes ‘1’ arguments
    No overload for method ‘ThirdStep’ takes ‘1’ arguments

    Where could be a problem?

    Like

    1. @Martin:

      I think you have created a form1 in different name.
      here in the above explaination the form name is “FirstStep”, where as in my application i have named my form as “Form1”

      replace the name of your form-1-name. with this u should be able to fix those errors.

      all these u have to do in ur form1.cs file… similarly with the case of form 2 and 3.

      public Form1(WizardData wd)
      {
      this.wData = wd;
      InitializeComponent();
      }

      Like

  6. First of all. Thanks very much for your useful post.

    I just came across your blog and wanted to drop you a note telling you how impressed I was with the

    information you have posted here.

    Please let me introduce you some info related to this post and I hope that it is useful for community.

    There is a good C# resource site, Have alook

    http://CSharpTalk.com

    Thanks again
    Rahul

    Like

  7. Thank you for this, but i have the problem .
    for example textBox1.text in the First Step(first Form) from to transfer textbox.text Secon step(second form) how can i do ? (form to form data transfer)

    Like

Please share your thoughts

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Power Spark

Power Spark By Shrangarika

Van Carl Nguyen

Exploration of Power Platform

My Trial

It is my experience timeline.

Power⚡Thomas

Sharing my knowledge and experience about the Microsoft Power Platform.

Arpit Power Guide

a guide to powering up community

Welcome to the Blog of Paul Andrew

Sponsored by Cloud Formations Ltd

Deriving Dynamics 365

Deriving Solutions and features on Power Platform/Dynamics 365

The CRM Ninja

Thoughts & musings from a Dynamics 365 Ninja!

D CRM Explorer

Learn about Microsoft Dynamics CRM Power Platform customization and implementation and other cool stuffs

Stroke // Jonas Rapp

I know pre-stroke. I will improve who I was.

Power Melange

Power Melange By Shalinee

Clavin's Blog

Power Automate - Power Apps - SharePoint Online - Azure - Nintex - K2 - Artificial Intelligence

Sat Sangha Salon

An Inquiry in Being

The Indoencers

The Influencers & Influences of Indian Music

Monika Halan's blog

Hand's-free money management

D365 Demystified

A closer look at Microsoft Dynamics 365.

Microsoft Mate (msftmate) - Andrew Rogers

Experienced consultant primarily focused on Microsoft Dynamics 365 and the Power Platform

Knowhere365

Specific topics by Django Lohn on the whole Microsoft365 Stack

Manmit Rahevar's Blog

One Stop Destination for Microsoft Technology Solutions

MG

Naturally Curious

Brian Illand

Power Platform and Dynamics 365

Steve Mordue MVP

A Microsoft Business Applications MVP

Subwoofer 101

Bass defines your home theater

SQLTwins by Nakul Vachhrajani

SQL Server tips and experiences dedicated to my twin daughters.

Everything D365

Discovering Azure DevOps and D365 Business Applications

Tech Wizard

Lets do IT Spells

XRM Tricks (Power Platform & Dynamics CRM )

Power Platform & Dynamics CRM

CRM TIPS BY PRM

Mail to crmtipsbyprm@gmail.com for queries and suggestions

nijos.dev

Giving back to the community what I have learned

xrm CRM Dynamics

Dynamics CRM Technical & Functional Info

Dynamics 365 Blogs - Explained in unique way

Sometimes you need to look at things from different perspective.

CRM Keeper

Dynamics 365 Customer Engagement, CRM, Microsoft CRM, Dynamics CRM