|
|||||||||||||||||||||||||
|
|||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionIn Windows Explorer under Windows XP, when you hide the Folder View, you get a rather snazy bar that contains a series of collapsible panels that provide shortcuts to common tasks based on the context of the current view. What I wanted was a control that emulates this functionality. What I came up with was an extendedSystem.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.
FeauturesCollapsiblePanelBar
CollapsiblePanel
DocumentationI haven't gone in to too much detail about the classes here, because there is some very comprehensive documentation available for download. The documentation has been built from the Visual Studio generated XML using NDoc, which is an approach I highly reccomend.Learning PointsThe following lists a few points I learnt whilst developing these classes:AttributesProperties can easily be grouped together in the property browser using the Category attribute, so you can put all of your custom properties into one category, or add them to an existing category, such as 'Appearance'.
[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.
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. StringsThis probably something you learn in chapter 1 or 2 of a C# programming book, but without one it may be a while before you pick it up (like me). If you place the '@' character before a string literal then characters will not be escaped, which makes it much easier to type and read things like file paths:
// @-quoted string
[ToolboxBitmap(@"C:\a\path\that\is\long\mybutton.bmp")]
// Normal string
[ToolboxBitmap("C:\\a\\path\\that\\is\\long\\mybutton.bmp")]
RegionsFor diehard C++ programmers (I used to be one) it can seem quite bizarre and very untidy to switch from separate headers and source files. However, for C# programmers help is at hand within Visual Studio. By using theregion 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.
Known ProblemsNone since version 1.3. Let me know if you find anything.TODO ListIn no particular order:
Update v1.2 21-Oct-2002
Upgrading from v1.1If you are starting from scratch then the code will be generated to cope with theISupportInitialize 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);
Update v1.3 23-Oct-2002
Update v1.3 30-Oct-2002Demo fixed. Update v1.4 19-Dec-2002
|
||||||||||||||||||||||||