Click here to Skip to main content
Click here to Skip to main content

Adding Custom Dialog to Visual Studio .NET 2003 Project

, 29 Jul 2007
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Sandeep. Vaidya
Web Developer
India India
I am a software engineer working from 1997 in differnt plotform and variety of applications.

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 30 Jul 2007
Article Copyright 2007 by Sandeep. Vaidya
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid