Click here to Skip to main content
15,892,737 members
Articles / Programming Languages / C#

Multiple Language Syntax Highlighting, Part 2: C# Control

Rate me:
Please Sign up or sign in to vote.
3.18/5 (16 votes)
12 Mar 20033 min read 247.9K   3K   69  
Fast and furious colorizing library for source code (C, C++, VBScript, JScript, xml, etc.)
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using ColorizerLibrary;
using System.Configuration;
using log4net;

namespace TextColorizerTest
{
	/// <summary>
	/// Description r�sum�e de [!output SAFE_CLASS_NAME].
	/// </summary>
	public class WebForm1 : System.Web.UI.Page
	{
		private static readonly ILog Log = LogManager.GetLogger( typeof(WebForm1) );
		protected System.Web.UI.HtmlControls.HtmlTextArea textArea;
		protected System.Web.UI.HtmlControls.HtmlInputButton ProcessBtn;
		protected ColorizerLibrary.Control.TextColorizerControl TextColorizerControl1;
		private CodeColorizer Colorizer;

		private void Page_Load(object sender, System.EventArgs e)
		{
			try
			{
				log4net.Config.DOMConfigurator.Configure();
				if (Log.IsInfoEnabled) Log.Info("Load page");

				Colorizer = ColorizerLibrary.Config.DOMConfigurator.Configure();
				TextColorizerControl1.SyntaxEngine = Colorizer;
			}
			catch( Exception exception)
			{
				Log.Fatal( exception );
				throw exception;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN�: Cet appel est requis par le Concepteur Web Form ASP.NET.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// M�thode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette m�thode avec l'�diteur de code.
		/// </summary>
		private void InitializeComponent()
		{    
			this.ProcessBtn.ServerClick += new System.EventHandler(this.ProcessBtn_ServerClick);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void ProcessBtn_ServerClick(object sender, System.EventArgs e)
		{
			if (Log.IsInfoEnabled) Log.Info("Button hit...");
			TextColorizerControl1.Text = textArea.InnerText;
		}
	}
}

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
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions