![]() |
Desktop Development »
Miscellaneous »
Miscellaneous Controls
Intermediate
Windows XP style Collapsible Panel BarBy Derek LakinExtended System.Windows.Forms.Panel classes for a collapsible panel and a panel bar to contain them, in a Windows XP style. |
C#.NET 1.0, Win2K, WinXP, Dev
|
|
Advanced Search Add to IE Search |
|
|
||||||||||||||||||

System.Windows.Forms.Panel class, CollapsiblePanel, that provides (as the name suggests) the collapsible panel functionality. CollapsiblePanel allows you to define a gradient fill for the background of the title bar, an image list for the expand/collapse button and an image to display on the left hand side (if you want).
To try and make this hang together as a Windows XP-like bar, I also created the CollapsiblePanelBar. This is another extended System.Windows.Forms.Panel, but this one adds some useful design-time support. As you add CollapsiblePanels to the CollapsiblePanelBar, it's anchor properties are set to Left, Right and Top and it's position is set just below the previous panel.
I'm currently developing on Windows NT, so properly rendering the panels with the current theme settings was irrelevant and so that feature remains on the TODO list.
[Category("MyProperties")]
public int MyProperty
{
get
{
return myInt;
}
set
{
myInt = value;
}
}
To add a description for your property into the property browser, use the Description attribute. This means that users of your control can get a better idea of the intent of the property.
[Category("MyProperties"),
Description("This property does something really useful")
public int MyProperty
{
get
{
return myInt;
}
set
{
myInt = value;
}
}
Runtime properties can be hidden in the property browser using the Browsable attribute. CollapsiblePanel does this for the PanelState property, which cannot be set at design time, because it wouldn't know what height to set the panel to when it was expanded.
false)>
public PanelState PanelState
{
...
}
If you're building a custom control (or inherited control) then you can specify a bitmap to use in the toolbox via the ToolboxBitmap attribute. This bitmap must be a 16 x 16 image in bitmap format.
[ToolboxBitmap(@"C:\mybutton.bmp")]
class MyButton : System.Windows.Forms.Button
{
...
}
Alternatively, you can use an image defined in another class:
[ToolboxBitmap(typeof(System.Windows.Forms.Button))]
class MyButton : System.Windows.Forms.Button
{
...
}
However, the easiest way to do this is just to name the custom bitmap the same as the control (i.e. MyButton.bmp for MyButton.cs). Then you don't even need to specifiy the ToolboxBitmap attribute, it does it all for you.
You can also define your own custom attributes; James T. Johnson has written an excellent article on this subject.
// @-quoted string
[ToolboxBitmap(@"C:\a\path\that\is\long\mybutton.bmp")]
// Normal string
[ToolboxBitmap("C:\\a\\path\\that\\is\\long\\mybutton.bmp")]
region name and endregion markers you can easily collapse sections of code. You can see from my source code that I have defined regions for things like Event Handlers, Public Properties, Public Methods, etc. You can even nest region blocks, which helps with things like nested classes or separate functional sections.
CollapsiblePanel at some point in the future.
CollapsiblePanel for contained items to ensure they are intially placed below the title bar (and possibly below that last item added). Maybe also set the achoring to Left, Top and Right.PanelIndex property to allow design time panel re-orderingSystem.ComponentModel.ISupportInitialize. This then causes the CollapsiblePanelBar to add panels to the end of the internal list (rather than the beginning) during the InitializeComponent call, thus negating the fact that the panels are added in reverse order.ImageIndex bug appears to have been an artifact of an earlier version and no longer appears any moreTitleText truncation (with an ellipsis) for narrow width panels.ISupportInitialize interface. If you are upgrading from v1.1 then you will need to modify your InitializeComponent function to add calls to BeginInit and EndInit:
((System.ComponentModel.ISupportInitialize)(this.myPanelBar)).BeginInit(); // v1.2
this.myPanelBar.SuspendLayout();
// ...
((System.ComponentModel.ISupportInitialize)(this.myPanelBar)).EndInit(); // v1.2
this.myPanelBar.ResumeLayout(false);
AutoScroll property is set to true then previously the wrong width would have been set for contained panels. This has also been fixed in this version.ToolboxBitmap attribute has been removed for both controls and the simpler approach described above has been used instead.Demo fixed.
CollapsiblePanel is disabled.CollapsiblePanelBar to enable it to contain panels derived from CollapsiblePanel (thanks to flipdoubt for pointing it out).
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 20 Dec 2002 Editor: Andrew Peace |
Copyright 2002 by Derek Lakin Everything else Copyright © CodeProject, 1999-2009 Web18 | Advertise on the Code Project |