Click here to Skip to main content
15,896,730 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 108.2K   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.Drawing;

namespace BinaryComponents.WinFormsGloss.Commands
{
	public class CommandRibbonButtonItem : Controls.Ribbon.ButtonItem, WinFormsUtility.Commands.ICommandControl
	{
		public CommandRibbonButtonItem( string text, Icon icon16, Icon icon24 )
			: base( text, icon16, icon24 )
		{
		}

		public CommandRibbonButtonItem( string text, Image image16, Image image24 )
			: base( text, image16, image24 )
		{
		}

		#region ICommandControl Members

		public WinFormsUtility.Commands.Command Command
		{
			get
			{
				return _command;
			}
			set
			{
				_command = value;

				UpdateState();
			}
		}

		public WinFormsUtility.Commands.CommandControlSet CommandControlSet
		{
			get
			{
				return _commandControlSet;
			}
			set
			{
				_commandControlSet = value;
			}
		}

		public void UpdateState()
		{
			if( _command == null )
			{
				Enabled = false;
			}
			else
			{
				Enabled = _command.IsEnabled();
			}
		}

		#endregion

		public override System.Windows.Forms.ToolStripItem CreateEquivalentToolStripItem()
		{
			string text = Text.Replace( "&", "&&" );

			WinFormsUtility.Commands.CommandToolStripMenuItem commandMenuItem = new WinFormsUtility.Commands.CommandToolStripMenuItem( text, _command );

			commandMenuItem.CommandControlSet = _commandControlSet;
			commandMenuItem.Image = Image16;

			return commandMenuItem;
		}

		protected override bool OnClick( Controls.Ribbon.Context context )
		{
			if( _command != null )
			{
				using( _commandControlSet.UsingCurrentInvocation() )
				{
					return _command.Invoke( Section.Ribbon );
				}
			}

			return false;
		}

		private WinFormsUtility.Commands.Command _command;
		private WinFormsUtility.Commands.CommandControlSet _commandControlSet;
	}
}

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