Click here to Skip to main content
15,894,337 members
Articles / Programming Languages / C# 4.0

Writing a P2P Snippet sharing Extension for Visual Studio 2010 (VSX 2010)

Rate me:
Please Sign up or sign in to vote.
4.50/5 (6 votes)
31 Mar 2010GPL311 min read 36.5K   332   21  
CodeXchange is a simple Visual Studio extension which allows you to create, edit and share snippets with your peers without leaving the Visual Studio 2010 IDE.
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Sand.Services.CodeXchange.Client.Controls
{
	/// <summary>
	/// The ExplorerBar is a Windows Explorer like control that supports sub 
	/// collapsible sub panels
	/// </summary>
	public class ExplorerBar : ScrollableControl , ISupportInitialize
	{
		private const int V_PADDING = 5;
		private const int H_PADDING = 5;

		private bool m_Initializing = false;
	
		public ExplorerBar()
		{
			Layout += new System.Windows.Forms.LayoutEventHandler(this.ExplorerBar_Layout);
			
			this.AutoScroll = true;
			//AutoCorrectMinimumExpandedHeight();
		}

		protected override void OnControlAdded(ControlEventArgs e)
		{
			base.OnControlAdded(e);

			if( e.Control is ExplorerGroup )
			{
				e.Control.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;

				((ExplorerGroup)e.Control).ExpandedChanged += new EventHandler(this.panel_IsExpandedChanged);
			}
		}

		private void panel_IsExpandedChanged(object sender, EventArgs e)
		{
			// if any control changes expansion state do a complete layout
			PerformLayout();
		}

		private void ExplorerBar_Layout(object sender, System.Windows.Forms.LayoutEventArgs e)
		{
			//only do the layou if initializing is complete
			if ( !m_Initializing )
			{
				// loop through all of the ExplorerGroup controls
				// and arrange them correctly
				for( int i = Controls.Count - 1; i >= 0; i-- )
				{
					ExplorerGroup group = Controls[i] as ExplorerGroup;

					if ( group != null )
					{
						// the first ExplorerBar get's placed at the top
						if( i == Controls.Count - 1 )
							group.Top = /*Top +*/ V_PADDING;
						else
							group.Top = Controls[i + 1].Bottom + V_PADDING;

						group.Left = H_PADDING;
						group.Width = Width - (2 * H_PADDING);

						// make room for the scroll bar
						if( VScroll )
							group.Width -= SystemInformation.VerticalScrollBarWidth;
					}
				}
			}
		}

		#region ISupportInitialize Members

		public void BeginInit()
		{
			m_Initializing = true;
		}

		public void EndInit()
		{
			m_Initializing = false;
		}

		#endregion
	}
}

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 GNU General Public License (GPLv3)


Written By
Software Developer
Spain Spain
Hi! I'm 22 years old. I live in a sunny mediterranian city called Barcelona.

I am a big fan of .NET and have been working with c# for a few years now.

Comments and Discussions