Click here to Skip to main content
15,896,201 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: Graphics object. Pin
Paul Riley11-Oct-02 2:10
Paul Riley11-Oct-02 2:10 
GeneralRe: Graphics object. Pin
Pete Bassett11-Oct-02 2:22
Pete Bassett11-Oct-02 2:22 
GeneralChanging permission set for CodeGroup Pin
EnkelIk10-Oct-02 23:18
EnkelIk10-Oct-02 23:18 
GeneralSeeking .NET Adoption Pin
Tariq10-Oct-02 22:36
Tariq10-Oct-02 22:36 
GeneralRe: Seeking .NET Adoption Pin
Kevin McFarlane11-Oct-02 4:52
Kevin McFarlane11-Oct-02 4:52 
GeneralRe: Seeking .NET Adoption Pin
Tariq12-Oct-02 8:21
Tariq12-Oct-02 8:21 
GeneralRe: Seeking .NET Adoption Pin
Matt Philmon16-Oct-02 12:35
Matt Philmon16-Oct-02 12:35 
GeneralDisappearing label Pin
Derek Lakin10-Oct-02 0:00
Derek Lakin10-Oct-02 0:00 
The following C# code is supposed to be an extended System.Windows.Forms.Panel class that provides a very basic implementation of the panels that Windows XP uses (when you take away the folder view in Explorer).

CollapsiblePanel simply contains two labels, one docked to the top for a title, and another anchored to the top right to display an expand/collapse image (the ImageList is exposed as a public property of the class).

At first glance, when you add a CollapsiblePanel to a Form it looks fine and seems to work okay. However, as soon as you add controls to the panel, the top right label with the image disappears WTF | :WTF:

Any ideas why?

using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace Salamander.Windows.Forms
{
	/// <summary>
	/// Summary description for CollapsiblePanel.
	/// </summary>
	public class CollapsiblePanel : System.Windows.Forms.Panel
	{
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label labelExpand;
		private System.Windows.Forms.Label labelTitle;
		private int panelHeight;

		#region Windows Form Designer generated code
		private void InitializeComponent()
		{
			this.labelTitle = new System.Windows.Forms.Label();
			this.labelExpand = new System.Windows.Forms.Label();
			this.SuspendLayout();
			// 
			// labelTitle
			// 
			this.labelTitle.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.labelTitle.Cursor = System.Windows.Forms.Cursors.Default;
			this.labelTitle.Dock = System.Windows.Forms.DockStyle.Top;
			this.labelTitle.Font = new System.Drawing.Font("Tahoma", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.labelTitle.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
			this.labelTitle.Name = "labelTitle";
			this.labelTitle.Size = new System.Drawing.Size(200, 24);
			this.labelTitle.TabIndex = 0;
			this.labelTitle.Text = "Title";
			this.labelTitle.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// labelExpand
			// 
			this.labelExpand.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right);
			this.labelExpand.BackColor = System.Drawing.SystemColors.ActiveCaption;
			this.labelExpand.Cursor = System.Windows.Forms.Cursors.Hand;
			this.labelExpand.Location = new System.Drawing.Point(17, 17);
			this.labelExpand.Name = "labelExpand";
			this.labelExpand.Size = new System.Drawing.Size(24, 24);
			this.labelExpand.TabIndex = 1;
			this.labelExpand.Click += new System.EventHandler(this.labelExpand_Click);
			// 
			// CollapsiblePanel
			// 
			this.Controls.AddRange(new System.Windows.Forms.Control[] {
																		  this.labelTitle,
																		  this.labelExpand});
			this.ResumeLayout(false);

		}
		#endregion
	
		/// <summary>
		/// Initialises a new instance of <a cref="Salamander.Windows.Forms.CollapsiblePanel">CollapsiblePanel</a>.
		/// </summary>
		public CollapsiblePanel() : base()
		{
			this.components = new System.ComponentModel.Container();

			InitializeComponent();

			// Set the background colour to ControlLightLight
			this.BackColor = SystemColors.ControlLightLight;
			
			// Set the size and position for the header
			this.labelExpand.Location = new System.Drawing.Point(this.Width - this.labelExpand.Width, 0);
			this.labelExpand.BringToFront();

			// Store the current panelHeight
			this.panelHeight = this.Height;
		}

		/// <summary>
		/// Gets the text displayed as the panel title.
		/// </summary>
		[Category("Title")]
		public string TitleText
		{
			get
			{
				return this.labelTitle.Text;
			}
			set
			{
				this.labelTitle.Text = value;
			}
		}

		/// <summary>
		/// Gets the background colour for the title bar.
		/// </summary>
		[Category("Title")]
		public Color TitleBackColour
		{
			get
			{
				return this.labelTitle.BackColor;
			}
			set
			{
				this.labelTitle.BackColor = value;
				this.labelExpand.BackColor = value;
			}
		}

		/// <summary>
		/// Gets the foreground colour used for the title bar.
		/// </summary>
		[Category("Title")]
		public Color TitleForeColour
		{
			get
			{
				return this.labelTitle.ForeColor;
			}
			set
			{
				this.labelTitle.ForeColor = value;
			}
		}

		/// <summary>
		/// Gets the font used for the title bar text.
		/// </summary>
		[Category("Title")]
		public Font TitleFont
		{
			get
			{
				return this.labelTitle.Font;
			}
			set
			{
				this.labelTitle.Font = value;
			}
		}

		/// <summary>
		/// Gets the image list used for the expand/collapse image.
		/// </summary>
		[Category("Title")]
		public ImageList ImageList
		{
			get
			{
				return this.labelExpand.ImageList;
			}
			set
			{
				this.labelExpand.ImageList = value;
			}
		}

		/// <summary>
		/// Gets the index into the image list of the currently displayed image.
		/// </summary>
		[Category("Title")]
		public int ImageIndex
		{
			get
			{
				return this.labelExpand.ImageIndex;
			}
			set
			{
				this.labelExpand.ImageIndex = value;
			}
		}

		private void labelExpand_Click(object sender, System.EventArgs e)
		{
			if((null != labelExpand.ImageList) && (labelExpand.ImageList.Images.Count >=2))
			{
				if(0 == labelExpand.ImageIndex)
				{
					// Currently expanded, so store the current height.
					this.panelHeight = this.Height;
					// Collapse the panel
					this.Height = labelTitle.Height;
					// Update the image.
					labelExpand.ImageIndex = 1;
				}
				else
				{
					// Currently collapsed, so expand the panel.
					this.Height = this.panelHeight;
					// Update the image.
					labelExpand.ImageIndex = 0;
				}
			}
		}
	}
}


Derek Lakin.
I wish I was what I thought I was when I wished I was what I am.

Salamander Software Ltd.
GeneralRe: Disappearing label Pin
David Stone10-Oct-02 5:11
sitebuilderDavid Stone10-Oct-02 5:11 
GeneralRe: Disappearing label Pin
Derek Lakin10-Oct-02 20:08
Derek Lakin10-Oct-02 20:08 
GeneralRe: Disappearing label Pin
Pete Bassett10-Oct-02 5:37
Pete Bassett10-Oct-02 5:37 
GeneralRe: Disappearing label Pin
Derek Lakin10-Oct-02 20:10
Derek Lakin10-Oct-02 20:10 
GeneralRe: Disappearing label Pin
Nnamdi Onyeyiri10-Oct-02 10:23
Nnamdi Onyeyiri10-Oct-02 10:23 
GeneralRe: Disappearing label Pin
Derek Lakin10-Oct-02 20:12
Derek Lakin10-Oct-02 20:12 
GeneralRe: Disappearing label Pin
Nnamdi Onyeyiri11-Oct-02 4:40
Nnamdi Onyeyiri11-Oct-02 4:40 
GeneralRe: Disappearing label Pin
Derek Lakin13-Oct-02 22:47
Derek Lakin13-Oct-02 22:47 
GeneralRe: Disappearing label Pin
Nnamdi Onyeyiri14-Oct-02 5:15
Nnamdi Onyeyiri14-Oct-02 5:15 
GeneralRe: Disappearing label Pin
Derek Lakin17-Oct-02 1:12
Derek Lakin17-Oct-02 1:12 
GeneralRe: Disappearing label Pin
Pete Bassett10-Oct-02 22:51
Pete Bassett10-Oct-02 22:51 
GeneralRe: Disappearing label Pin
Derek Lakin17-Oct-02 1:09
Derek Lakin17-Oct-02 1:09 
QuestionCompiler classes? Pin
Jörgen Sigvardsson9-Oct-02 13:46
Jörgen Sigvardsson9-Oct-02 13:46 
AnswerRe: Compiler classes? Pin
Daniel Turini11-Oct-02 0:02
Daniel Turini11-Oct-02 0:02 
GeneralRe: Compiler classes? Pin
Jörgen Sigvardsson11-Oct-02 0:03
Jörgen Sigvardsson11-Oct-02 0:03 
GeneralMFC App using a .NET Form Pin
phreds_phancy9-Oct-02 9:01
phreds_phancy9-Oct-02 9:01 
QuestionAddStrip??? Pin
Stan Shannon9-Oct-02 2:55
Stan Shannon9-Oct-02 2:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.