Click here to Skip to main content
15,891,865 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 108K   23   115  
A tree control implementation, allowing complete customization and animation support
/////////////////////////////////////////////////////////////////////////////
//
// (c) 2007 BinaryComponents Ltd.  All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
//
// (c) 2006 BinaryComponents Ltd.  All Rights Reserved.
//
// http://www.binarycomponents.com/
//
/////////////////////////////////////////////////////////////////////////////

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Drawing.Drawing2D;

namespace BinaryComponents.VectorGraphics.TestHarness
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();

			SetStyle
				( ControlStyles.AllPaintingInWmPaint
				| ControlStyles.OptimizedDoubleBuffer
				, true );

			_renderer = new Renderers.GdiPlusRenderer( CreateGraphics, Renderers.GdiPlusRenderer.MarkerHandling.Display, 5 );

			Create();
		}

		protected override bool ProcessCmdKey( ref Message msg, Keys keyData )
		{
			if( keyData == Keys.F5 )
			{
				Create();
				Invalidate();
				return true;
			}

			return base.ProcessCmdKey( ref msg, keyData );
		}

		private void Create()
		{
			Factories.Rectangle rectangleFactory = new Factories.Rectangle();
			Factories.RoundedRectangle roundedRectangleFactory = new Factories.RoundedRectangle();
			Factories.SoftShadow softShadowFactory = new Factories.SoftShadow( _renderer, new Types.Point( 2, 2 ), 4, new Paint.Color( 0, 0, 0, 0.4 ) );
			Factories.GlossyBrush glossyBrush = new Factories.GlossyBrush();

			Random random = new Random();
			Styles.StyleSet style = new StyleSets.BlueAndWhite();

			_container = new Primitives.Container();

			//
			// Create pie chart.

			int pieParts = 5;
			Graphs.StaticData pieChartData = new Graphs.StaticData( pieParts, 1 );

			for( int i = 0; i < pieParts; ++i )
			{
			  pieChartData[i, 0] = random.NextDouble();
			}

			pieChartData.SetRowExtra( 2, "Exploded", "true" );

			Graphs.PieChart.Settings pieChartSettings = new Graphs.PieChart.Settings();

			pieChartSettings.Width = 200;
			pieChartSettings.Height = 200;

			Primitives.Container pieChartContainer = new Primitives.Container( new Types.Point( 10, 10 ) );

			Graphs.PieChart pieChart = new Graphs.PieChart();

			pieChartContainer.AddBack( pieChart.Create( pieChartData, pieChartSettings ) );

			style.Apply( _renderer, pieChartContainer );

			_container.AddBack( pieChartContainer );

			//
			// Create bar chart.

			int barGroups = 5;
			int barParts = 3;
			Graphs.StaticData barChartData = new Graphs.StaticData( barGroups, barParts );

			for( int i = 0; i < barGroups; ++i )
			{
			  for( int j = 0; j < barParts; ++j )
			  {
			    barChartData[i, j] = random.NextDouble();
			  }
			}

			Graphs.BarChart.Settings barChartSettings = new Graphs.BarChart.Settings();

			barChartSettings.Width = 200;
			barChartSettings.Height = 200;

			Primitives.Container barChartContainer = new Primitives.Container( new Types.Point( 220, 10 ) );

			Graphs.BarChart barChart = new Graphs.BarChart();

			barChartContainer.AddBack( barChart.Create( barChartData, barChartSettings ) );

			style.Apply( _renderer, barChartContainer );

			_container.AddBack( barChartContainer );

			//
			// Create line chart.

			int lines = 2;
			int columns = 10;
			Graphs.StaticData lineChartData = new Graphs.StaticData( columns, lines + 1 );

			for( int i = 0; i < columns; ++i )
			{
				lineChartData[i, 0] = i;
				lineChartData.SetRowExtra( i, "LABEL", i.ToString() );
			}
			for( int i = 1; i < lines + 1; ++i )
			{
				for( int j = 0; j < columns; ++j )
				{
					lineChartData[j, i] = random.NextDouble() - 0.5;
				}
			}

			Graphs.LineChart.Settings lineChartSettings = new Graphs.LineChart.Settings();

			lineChartSettings.Width = 200;
			lineChartSettings.Height = 200;

			Primitives.Container lineChartContainer = new Primitives.Container( new Types.Point( 440, 10 ) );

			Graphs.LineChart lineChart = new Graphs.LineChart();

			lineChartContainer.AddBack( lineChart.Create( lineChartData, lineChartSettings ) );

			style.Apply( _renderer, lineChartContainer );

			_container.AddBack( lineChartContainer );
		}

		protected override void OnPaint( PaintEventArgs e )
		{
			_renderer.Render( e.Graphics, _container, new Types.Rectangle( e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height ) );
		}

		private Renderers.GdiPlusRenderer _renderer;
		private Primitives.Container _container;
	}
}

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