Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Adding Custom Dialog to Visual Studio .NET 2003 Project

0.00/5 (No votes)
29 Jul 2007 1  
Visual Studio custom action provides the option to add predefined custom dialogs, however there is no option to add our own custom dialog. The following class can be used to add the custom dialog. We can create a DLL using the following class and custom dialogs.

Introduction

This is useful when custom actions are required in the installer while Visual Studio .NET 2003 is used to build the setup using the setup/deployment project.

Background

Visual Studio 2003 does not have an option to add the custom dialogs. It has some predefined dialogs which can be used for any custom actions. If we want to have our own custom dialog, we have to follow the class given below.

Using the Code

This is a generic class which can be used as given here. We need to create a project resulting in a DLL and add this class to the project. Add multiple dialogs required to be launched at the end of the installation.

using System;
using System.Configuration.Install;
using System.ComponentModel;
using System.Collections;
using System.Windows.Forms;

namespace CustomDialogLauncherSpace
{
     /// <summary>
     /// Summary for Custom Dialof launcher
     /// </summary>
     [RunInstallerAttribute(true)]
     public class CustomDialogLauncher : System.Configuration.Install.Installer
     {
          private string InstallDir;
          public CustomDialogLauncher()
         {
              //
              // TODO: Add constructor logic here
              //
         }
 
         // Overridden Install method which will get called first.
         public override void Install(IDictionary savedState)
        { 
              base.Install(savedState);
              // Get the install path
              string TheAssemblyPath = this.Context.Parameters["assemblypath"];
              InstallDir = TheAssemblyPath.Substring
			(0, TheAssemblyPath.LastIndexOf("\\"));
              // Display the custom dialog

              // If you want you can use InstallDir else, skip
              CustomDialog custDialog = new CustomDialog(InstallDir);
              DialogResult result = custDialog.ShowDialog();
              if(result != DialogResult.OK)
              {
                   DialogResult rollBack = MessageBox.Show
			("This will roll back the installation, are you sure", 
			"Installation", MessageBoxButtons.YesNo, 
			MessageBoxIcon.Question);
                   if(DialogResult.Yes == rollBack)
                   {
                       throw new InstallException("Installation aborted, rolling back");
                   }
               }
         }

         // Overridden Uninstall method which will get called during un install.
         public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
        // Overridden Rollback method which will get called 
        // during installation rollback
        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }
        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);
        }
    }
}

Add the multiple custom dialogs required in the setup project in the same project. Call all the dialogs in the Install() function in the sequence required. Once the new DLL is created, add the DLL to Application folder using Add Custom action. Select the Add file button to add the newly built DLL.

History

  • 30th July, 2007: Initial post 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here