Click here to Skip to main content
15,881,172 members
Articles / Programming Languages / C#

Integrating Help into Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
4.54/5 (28 votes)
17 Jan 20043 min read 158K   1.3K   106  
Document your C# code and have on-the-fly help directly integrated into Visual Studio .NET.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using Microsoft.Win32;

namespace VS.NET_Help_Integrator
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.FolderBrowserDialog fbdProjectDir;
		private System.Windows.Forms.TextBox tbProjectDir;
		private System.Windows.Forms.Button bProjectDirBrowse;
		private System.Windows.Forms.Label lProjectDir;
		private System.Windows.Forms.Label lNamespaceName;
		private System.Windows.Forms.MenuItem miFile;
		private System.Windows.Forms.MenuItem miFileExit;
		private System.Windows.Forms.MenuItem miHelp;
		private System.Windows.Forms.MenuItem miHelpAbout;
		private System.Windows.Forms.MainMenu MainMenu;
		private System.Windows.Forms.TextBox tbNamespaceName;
		private System.Windows.Forms.Label lNamespaceDescription;
		private System.Windows.Forms.TextBox tbNamespaceDescription;
		private System.Windows.Forms.OpenFileDialog ofdHelpCollection;
		private System.Windows.Forms.Button bHelpCollectionBrowse;
		private System.Windows.Forms.Label lHelpCollection;
		private System.Windows.Forms.TextBox tbHelpCollection;
		private System.Windows.Forms.Button bGenerate;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		private String H2RegPath;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
			this.tbProjectDir = new System.Windows.Forms.TextBox();
			this.fbdProjectDir = new System.Windows.Forms.FolderBrowserDialog();
			this.bProjectDirBrowse = new System.Windows.Forms.Button();
			this.lProjectDir = new System.Windows.Forms.Label();
			this.lNamespaceName = new System.Windows.Forms.Label();
			this.MainMenu = new System.Windows.Forms.MainMenu();
			this.miFile = new System.Windows.Forms.MenuItem();
			this.miFileExit = new System.Windows.Forms.MenuItem();
			this.miHelp = new System.Windows.Forms.MenuItem();
			this.miHelpAbout = new System.Windows.Forms.MenuItem();
			this.tbNamespaceName = new System.Windows.Forms.TextBox();
			this.lNamespaceDescription = new System.Windows.Forms.Label();
			this.tbNamespaceDescription = new System.Windows.Forms.TextBox();
			this.ofdHelpCollection = new System.Windows.Forms.OpenFileDialog();
			this.bHelpCollectionBrowse = new System.Windows.Forms.Button();
			this.lHelpCollection = new System.Windows.Forms.Label();
			this.tbHelpCollection = new System.Windows.Forms.TextBox();
			this.bGenerate = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// tbProjectDir
			// 
			this.tbProjectDir.Location = new System.Drawing.Point(136, 24);
			this.tbProjectDir.Name = "tbProjectDir";
			this.tbProjectDir.Size = new System.Drawing.Size(168, 20);
			this.tbProjectDir.TabIndex = 0;
			this.tbProjectDir.Text = "";
			this.tbProjectDir.TextChanged += new System.EventHandler(this.UpdateGenerateButton);
			// 
			// bProjectDirBrowse
			// 
			this.bProjectDirBrowse.Location = new System.Drawing.Point(304, 24);
			this.bProjectDirBrowse.Name = "bProjectDirBrowse";
			this.bProjectDirBrowse.Size = new System.Drawing.Size(56, 20);
			this.bProjectDirBrowse.TabIndex = 5;
			this.bProjectDirBrowse.Text = "&Browse";
			this.bProjectDirBrowse.Click += new System.EventHandler(this.bProjectDirBrowse_Click);
			// 
			// lProjectDir
			// 
			this.lProjectDir.Location = new System.Drawing.Point(8, 24);
			this.lProjectDir.Name = "lProjectDir";
			this.lProjectDir.Size = new System.Drawing.Size(128, 16);
			this.lProjectDir.TabIndex = 7;
			this.lProjectDir.Text = "Project Directory";
			// 
			// lNamespaceName
			// 
			this.lNamespaceName.Location = new System.Drawing.Point(8, 48);
			this.lNamespaceName.Name = "lNamespaceName";
			this.lNamespaceName.Size = new System.Drawing.Size(128, 16);
			this.lNamespaceName.TabIndex = 8;
			this.lNamespaceName.Text = "Namespace Name";
			// 
			// MainMenu
			// 
			this.MainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					 this.miFile,
																					 this.miHelp});
			// 
			// miFile
			// 
			this.miFile.Index = 0;
			this.miFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																				   this.miFileExit});
			this.miFile.Text = "&File";
			// 
			// miFileExit
			// 
			this.miFileExit.Index = 0;
			this.miFileExit.Text = "E&xit";
			this.miFileExit.Click += new System.EventHandler(this.miFileExit_Click);
			// 
			// miHelp
			// 
			this.miHelp.Index = 1;
			this.miHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																				   this.miHelpAbout});
			this.miHelp.Text = "&Help";
			// 
			// miHelpAbout
			// 
			this.miHelpAbout.Index = 0;
			this.miHelpAbout.Text = "&About...";
			this.miHelpAbout.Click += new System.EventHandler(this.miHelpAbout_Click);
			// 
			// tbNamespaceName
			// 
			this.tbNamespaceName.Location = new System.Drawing.Point(136, 48);
			this.tbNamespaceName.Name = "tbNamespaceName";
			this.tbNamespaceName.Size = new System.Drawing.Size(168, 20);
			this.tbNamespaceName.TabIndex = 1;
			this.tbNamespaceName.Text = "";
			this.tbNamespaceName.TextChanged += new System.EventHandler(this.UpdateGenerateButton);
			// 
			// lNamespaceDescription
			// 
			this.lNamespaceDescription.Location = new System.Drawing.Point(8, 72);
			this.lNamespaceDescription.Name = "lNamespaceDescription";
			this.lNamespaceDescription.Size = new System.Drawing.Size(128, 16);
			this.lNamespaceDescription.TabIndex = 9;
			this.lNamespaceDescription.Text = "Namespace Description";
			// 
			// tbNamespaceDescription
			// 
			this.tbNamespaceDescription.Location = new System.Drawing.Point(136, 72);
			this.tbNamespaceDescription.Name = "tbNamespaceDescription";
			this.tbNamespaceDescription.Size = new System.Drawing.Size(168, 20);
			this.tbNamespaceDescription.TabIndex = 2;
			this.tbNamespaceDescription.Text = "";
			this.tbNamespaceDescription.TextChanged += new System.EventHandler(this.UpdateGenerateButton);
			// 
			// ofdHelpCollection
			// 
			this.ofdHelpCollection.DefaultExt = "HxC";
			this.ofdHelpCollection.Filter = "HTML Help 2 Files|*.HxC";
			// 
			// bHelpCollectionBrowse
			// 
			this.bHelpCollectionBrowse.Location = new System.Drawing.Point(304, 96);
			this.bHelpCollectionBrowse.Name = "bHelpCollectionBrowse";
			this.bHelpCollectionBrowse.Size = new System.Drawing.Size(56, 20);
			this.bHelpCollectionBrowse.TabIndex = 6;
			this.bHelpCollectionBrowse.Text = "B&rowse";
			this.bHelpCollectionBrowse.Click += new System.EventHandler(this.bHelpCollectionBrowse_Click);
			// 
			// lHelpCollection
			// 
			this.lHelpCollection.Location = new System.Drawing.Point(8, 96);
			this.lHelpCollection.Name = "lHelpCollection";
			this.lHelpCollection.Size = new System.Drawing.Size(128, 16);
			this.lHelpCollection.TabIndex = 10;
			this.lHelpCollection.Text = "Help Collection";
			// 
			// tbHelpCollection
			// 
			this.tbHelpCollection.Location = new System.Drawing.Point(136, 96);
			this.tbHelpCollection.Name = "tbHelpCollection";
			this.tbHelpCollection.Size = new System.Drawing.Size(168, 20);
			this.tbHelpCollection.TabIndex = 3;
			this.tbHelpCollection.Text = "";
			this.tbHelpCollection.TextChanged += new System.EventHandler(this.UpdateGenerateButton);
			// 
			// bGenerate
			// 
			this.bGenerate.Enabled = false;
			this.bGenerate.Location = new System.Drawing.Point(288, 136);
			this.bGenerate.Name = "bGenerate";
			this.bGenerate.Size = new System.Drawing.Size(72, 24);
			this.bGenerate.TabIndex = 4;
			this.bGenerate.Text = "&Generate";
			this.bGenerate.Click += new System.EventHandler(this.bGenerate_Click);
			// 
			// MainForm
			// 
			this.AcceptButton = this.bGenerate;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(370, 171);
			this.Controls.Add(this.bGenerate);
			this.Controls.Add(this.tbHelpCollection);
			this.Controls.Add(this.lHelpCollection);
			this.Controls.Add(this.bHelpCollectionBrowse);
			this.Controls.Add(this.tbNamespaceDescription);
			this.Controls.Add(this.lNamespaceDescription);
			this.Controls.Add(this.tbNamespaceName);
			this.Controls.Add(this.lNamespaceName);
			this.Controls.Add(this.lProjectDir);
			this.Controls.Add(this.bProjectDirBrowse);
			this.Controls.Add(this.tbProjectDir);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Menu = this.MainMenu;
			this.MinimizeBox = false;
			this.Name = "MainForm";
			this.RightToLeft = System.Windows.Forms.RightToLeft.No;
			this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "VS.NET Help Integrator";
			this.Closing += new System.ComponentModel.CancelEventHandler(this.MainForm_Closing);
			this.Load += new System.EventHandler(this.MainForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new MainForm());
		}

		private void bProjectDirBrowse_Click(object sender, System.EventArgs e)
		{
			fbdProjectDir.SelectedPath = tbProjectDir.Text;
			if(fbdProjectDir.ShowDialog() == DialogResult.OK)
				tbProjectDir.Text = fbdProjectDir.SelectedPath;
		}

		private void miHelpAbout_Click(object sender, System.EventArgs e)
		{
			using(AboutForm af = new AboutForm())
			{
				af.ShowDialog();
			}
		}

		private void bHelpCollectionBrowse_Click(object sender, System.EventArgs e)
		{
			if(ofdHelpCollection.ShowDialog() == DialogResult.OK)
				tbHelpCollection.Text = Path.GetFileName(ofdHelpCollection.FileName);
		}

		private void miFileExit_Click(object sender, System.EventArgs e)
		{
			Close();
			Application.Exit();
		}

		private void UpdateGenerateButton(object sender, System.EventArgs e)
		{
			bGenerate.Enabled =
				tbProjectDir.Text.Length > 0 &&
				tbNamespaceName.Text.Length > 0 &&
				tbNamespaceDescription.Text.Length > 0 &&
				tbHelpCollection.Text.Length > 0;
		}

		private void bGenerate_Click(object sender, System.EventArgs e)
		{
			if(!Directory.Exists(Path.Combine(tbProjectDir.Text,"Help")))
				Directory.CreateDirectory(Path.Combine(tbProjectDir.Text,"Help"));
			try
			{
				using(StreamWriter sw = new StreamWriter(Path.Combine(tbProjectDir.Text,"Help\\H2Reg.ini"))) 
				{
					sw.WriteLine("; Register (-r switch)");
					sw.WriteLine("[Reg_Namespace]");
					sw.WriteLine(tbNamespaceName.Text + "|" + tbHelpCollection.Text + "|" + tbNamespaceDescription.Text);
					sw.WriteLine();
					sw.WriteLine("[Reg_Title]");
					sw.WriteLine(tbNamespaceName.Text + "|" + tbNamespaceName.Text + "|" +
						"1033|" + tbHelpCollection.Text + "|||||||");
					sw.WriteLine();
					sw.WriteLine("; Unregister (-u switch)");
					sw.WriteLine("[UnReg_Namespace]");
					sw.WriteLine(tbNamespaceName.Text);
					sw.WriteLine();
					sw.WriteLine("[UnReg_Title]");
					sw.WriteLine(tbNamespaceName.Text + "|" + tbNamespaceName.Text + "|1033");
				}

				using(StreamWriter sw = new StreamWriter(Path.Combine(tbProjectDir.Text,"Help\\Register.bat"))) 
				{
					sw.WriteLine("@echo off");
					sw.WriteLine("REM Registers " + tbNamespaceName.Text + " in HTML 2 Help");
					sw.WriteLine("copy ..\\doc\\*.hxS");
					sw.WriteLine("copy ..\\doc\\*.hxC");
					sw.WriteLine("\"" + Path.Combine(H2RegPath,"H2Reg.exe") + "\" -r cmdfile=\"" + Path.Combine(tbProjectDir.Text,"Help\\H2Reg.ini") + "\"");
				}

				using(StreamWriter sw = new StreamWriter(Path.Combine(tbProjectDir.Text,"Help\\Unregister.bat"))) 
				{
					sw.WriteLine("@echo off");
					sw.WriteLine("REM Unregisters " + tbNamespaceName.Text + " in HTML 2 Help");
					sw.WriteLine("\"" + Path.Combine(H2RegPath,"H2Reg.exe") + "\" -u cmdfile=\"" + Path.Combine(tbProjectDir.Text,"Help\\H2Reg.ini") + "\"");
				}
			}
			catch(Exception)
			{
				return;
			}

			MessageBox.Show(this,"The files have been created successfully.");
		}

		private void MainForm_Load(object sender, System.EventArgs e)
		{
			RegistryKey rk = Registry.LocalMachine;
			RegistryKey h2reg = rk.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\H2Refxx_is1");
			if(h2reg == null)
			{
				MessageBox.Show(this,"H2Reg is not installed. Please install it before running this program.");
				Application.Exit();
			}
			H2RegPath = (String)h2reg.GetValue("Inno Setup: App Path");

			RegistryKey reg = Registry.CurrentUser.OpenSubKey("Software\\Tanis\\VS.NET Help Integrator",true);
			if(reg != null)
			{
				try
				{
					tbProjectDir.Text = (String)reg.GetValue("Project Dir");
					tbNamespaceName.Text = (String)reg.GetValue("Namespace Name");
					tbNamespaceDescription.Text = (String)reg.GetValue("Namespace Description");
					tbHelpCollection.Text = (String)reg.GetValue("Help Collection");
				}
				finally
				{
					reg.Close();
				}
			}
		}

		private void MainForm_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			RegistryKey reg = Registry.CurrentUser.CreateSubKey("Software\\Tanis\\VS.NET Help Integrator");
			try
			{
				reg.SetValue("Project Dir",tbProjectDir.Text);
				reg.SetValue("Namespace Name",tbNamespaceName.Text);
				reg.SetValue("Namespace Description",tbNamespaceDescription.Text);
				reg.SetValue("Help Collection",tbHelpCollection.Text);
			}
			finally
			{
				reg.Close();
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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


Written By
Team Leader momondo
Denmark Denmark
Sune has been programming since 1985.

He has worked with both assembler and many different programming languages, such as: Basic, Fortran, Pascal, C, C++, Delphi, and lately C#.

Sune is married and has two small children and is currently working as a developer for a Danish company called Skygate, currenly working on a cheap flight search engine called Momondo.

Personal blog can be found here.

Comments and Discussions