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.
This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)