Click here to Skip to main content
15,885,546 members
Articles / Multimedia / GDI+

Customizable Tree Control with Animation Support

Rate me:
Please Sign up or sign in to vote.
4.72/5 (17 votes)
8 Apr 2008CPOL4 min read 107.7K   23   115  
A tree control implementation, allowing complete customization and animation support
/////////////////////////////////////////////////////////////////////////////
//
// (c) 2007 BinaryComponents Ltd.  All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;

namespace BinaryComponents.WinFormsUtility.Commands
{
	public class KeyCommandLauncherFactory
	{
		public KeyCommandLauncherFactory( Utility.Assemblies.ManifestResources resources,
						string prefix, CommandControlSet commandControlSet )
			: this( resources, System.Reflection.Assembly.GetCallingAssembly(), prefix, commandControlSet )
		{
		}

		public KeyCommandLauncherFactory( Utility.Assemblies.ManifestResources resources,
				System.Reflection.Assembly assembly, string prefix, CommandControlSet commandControlSet )
		{
			if( assembly == null )
			{
				throw new ArgumentNullException( "assembly" );
			}
			if( prefix == null )
			{
				throw new ArgumentNullException( "prefix" );
			}
			if( commandControlSet == null )
			{
				throw new ArgumentNullException( "commandControlSet" );
			}
			if( resources == null )
			{
				throw new ArgumentNullException( "resources" );
			}

			_resources = resources;
			_assembly = assembly;
			_prefix = prefix;
			_commandControlSet = commandControlSet;
		}

		public void Create( XmlDocument xmlDoc, KeyCommandLauncher keyCommandLauncher )
		{
			foreach( XmlNode keyCommandNode in xmlDoc.SelectNodes( "/KeyCommands/KeyCommand" ) )
			{
				string keyText = keyCommandNode.Attributes["Key"].Value;
				string commandText = keyCommandNode.Attributes["Command"].Value;

				Command command = CreateCommand( commandText );
				Keys keys = Keys.None;

				string[] keyTextParts = keyText.Split( '+' );

				foreach( string keyTextPart in keyTextParts )
				{
					switch( keyTextPart )
					{
						case "Ctrl":
							keys |= Keys.Control;
							break;
						case "Shift":
							keys |= Keys.Shift;
							break;
						case "Alt":
							keys |= Keys.Alt;
							break;
						default:
							keys |= (Keys) Enum.Parse( typeof( Keys ), keyTextPart );
							break;
					}
				}

				keyCommandLauncher.Add( keys, command );
			}
		}

		protected virtual Command CreateCommand( string name )
		{
			string fullname = Prefix + name;

			Command command = (Command) _assembly.CreateInstance
					( fullname, false, System.Reflection.BindingFlags.CreateInstance, null
					,	CommandConstructorArguments, null, null );

			if( command == null )
			{
				throw new XmlException( string.Format( "Failed to create command '{0}'.", fullname ) );
			}

			return command;
		}

		protected virtual object[] CommandConstructorArguments
		{
			get
			{
				return new object[] { };
			}
		}

		protected string Prefix
		{
			get
			{
				return _prefix;
			}
		}

		private System.Reflection.Assembly _assembly;
		private string _prefix;
		private CommandControlSet _commandControlSet;
		private Utility.Assemblies.ManifestResources _resources;
	}
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
I'm currently working for a small start-up company, BinaryComponents Ltd, producing the FeedGhost RSS reader.

FeedGhost RSS Reader:
http://www.feedghost.com

Bespoke Software Development
http://www.binarycomponents.com

Comments and Discussions