BinaryHeaderControl
A panel with an Outlook-style caption band – and an optional footer band – drawn across one of its edges, used to give a group of controls a titled, collapsible, colour-themed frame such as a navigation pane, a task pane or a "Folders" box.
public partial class BinaryHeaderControl : Panel
Inherits from / implements: Panel
Remarks
What it is for
Drop the controls of one pane – a tree of mail folders, a list of tasks, a set of filter
options – onto a BinaryHeaderControl and they get a titled frame: a gradient caption
band with an optional icon, a gradient client area behind them, a border, and optionally a footer
band, a drop shadow, and a button at the end of the caption that either collapses the pane to its
caption or opens a menu of commands for it.
Key concepts
- The bands are outside the client area. The caption and the footer are drawn in
the window's frame, so docked and anchored children start below the caption and stop above the footer
without any margin of your own.
HeaderLocationputs the caption along the top, bottom, left or right edge; on the left and right the band and its text are turned on their side. - One button, two jobs. The button at the end of the caption is either the
collapse button (
EnableCollapseExpandButton, on by default) or the context menu button (EnableHeaderContextMenu). Turning either on turns the other off. - Colour schemes.
ColorSchemesets the caption, footer, background and border colours in one go. ChooseColorScheme.Noneto keep colours of your own. - No scrolling of its own.
AutoScrollis alwaysfalse. Put aBinaryScrollablePanelinside the control and the controls on that panel when the content can be longer than the pane.
How to use it
Set HeaderText (and HeaderIcon or HeaderImage), choose
a ColorScheme, add the pane's controls, and handle HeaderClicked,
FooterClicked or HeaderContextMenuAboutToBeDisplayed as needed.
Appearance
HeaderFooterDrawingStyle chooses between a plain two-colour gradient and an Office
style two-tone band. The caption and footer each have a gradient (StartColorForHeaderRendering,
EndColorForHeaderRendering, HeaderGradientDrawingDirection, and the footer
equivalents), a font, a text colour and an optional inner border (DrawBorderAround). The
client area is painted with StartColorForBackgroundRendering to
EndColorForBackgroundRendering. ShouldDrawDropShadow adds a soft shadow
along the bottom and right edges.
Band heights are in logical pixels (1/96 inch) and are scaled with the display; a band is never made shorter than one line of its caption font.
Examples
A "Mail folders" pane docked down the left of a form, with a footer, a scrolling folder list and a context menu of folder commands.
using System.Drawing;
using System.Windows.Forms;
using Binarymission.WinForms.Controls.NavigationControls;
public class MailForm : Form
{
private readonly ListBox folders = new ListBox();
private readonly ToolStripMenuItem emptyDeletedItems = new ToolStripMenuItem("Empty Deleted Items");
public MailForm()
{
Text = "Mail";
Size = new Size(900, 600);
var menu = new ContextMenuStrip();
menu.Items.Add("New folder...");
menu.Items.Add(emptyDeletedItems);
var pane = new BinaryHeaderControl
{
Dock = DockStyle.Left,
Width = 240,
ColorScheme = ColorScheme.Blue,
HeaderFooterDrawingStyle = HeaderFooterDrawingStyle.OfficeStyle,
HeaderText = "Mail folders",
HeaderCaptionFont = new Font("Segoe UI", 10f, FontStyle.Bold),
HeaderTextForeColor = Color.Navy,
EnableHeaderContextMenu = true, // the caption button opens HeaderContextMenuStrip
HeaderContextMenuStrip = menu,
DrawFooter = true, // set before FooterText: the text is ignored without a footer
FooterText = "3 unread in Inbox",
ShouldDrawDropShadow = true,
};
// The pane does not scroll by itself; a BinaryScrollablePanel fills its client area.
var scroller = new BinaryScrollablePanel();
folders.Dock = DockStyle.Fill;
folders.Items.AddRange(new object[] { "Inbox", "Drafts", "Sent Items", "Deleted Items", "Archive" });
scroller.Controls.Add(folders);
pane.Controls.Add(scroller);
pane.HeaderClicked += (s, e) => folders.Focus();
pane.HeaderContextMenuAboutToBeDisplayed += OnFolderMenuOpening;
Controls.Add(pane);
}
private void OnFolderMenuOpening(object sender, ref bool cancel)
{
emptyDeletedItems.Enabled = (string)folders.SelectedItem == "Deleted Items";
}
}See also
Members at a glance
| Constructors | |
|---|---|
BinaryHeaderControl | Initialises a new BinaryHeaderControl with the
ColorScheme.Blue colour scheme, the caption across the top and the
collapse button showing. |
| Properties | |
AutoScroll | Gets whether the client area scrolls; it never does. |
BackgroundGradientDrawingDirection | Gets or sets the direction in which the client area's background gradient runs. |
BorderColor | Gets or sets the colour of the border drawn round the whole control. |
BorderStyle | Gets the standard Windows border style, which is always BorderStyle.None. |
BorderWidth | Gets or sets the thickness of the border drawn round the whole control. |
ColorScheme | Gets or sets the built-in palette the caption, footer, background, border and context menu button are drawn in. |
ContextMenuArrowColor | Gets or sets the colour of the arrow inside the built-in context menu button. |
ContextMenuEllipseColor | Gets or sets the colour of the round body of the built-in context menu button. |
ContextMenuImageType | Gets or sets which picture is drawn as the context menu button: the built-in round button, your icon or your bitmap. |
ContextMenuType | Gets or sets which of the two menu properties the context menu button opens. |
ControlIsInExpandedState | Gets or sets whether the control is expanded, as opposed to collapsed to its caption. |
CustomContextMenuButtonImageTransparencyColor | Gets or sets the colour in CustomImageForContextMenuButton that is made transparent, so
that the caption shows through the picture's background. |
CustomIconForContextMenuButton | Gets or sets the icon drawn as the context menu button when
ContextMenuImageType is ContextMenuButtonImageType.Icon. |
CustomImageForContextMenuButton | Gets or sets the picture drawn as the context menu button when
ContextMenuImageType is ContextMenuButtonImageType.Bitmap. |
DisplayRectangle | Gets the area available to the hosted controls, in client coordinates. |
DrawBorderAround | Gets or sets which bands – the caption, the footer, both or neither – have a border drawn just inside their edges. |
DrawFooter | Gets or sets whether a footer band is drawn along the edge opposite the caption. |
DropShadowColor | Gets or sets the colour of the drop shadow. |
DropShadowDepth | Gets or sets how far the drop shadow reaches beyond the frame. |
DropShadowOpacity | Gets or sets how dark the drop shadow is where it is strongest, next to the frame. |
EnableCollapseExpandButton | Gets or sets whether the caption shows a round button that collapses the control to its caption and expands it again. |
EnableHeaderContextMenu | Gets or sets whether the caption shows a round button that opens a menu of commands for the pane. |
EndColorForBackgroundRendering | Gets or sets the colour the client area's background gradient ends with. |
EndColorForFooterRendering | Gets or sets the colour the footer band's gradient ends with. |
EndColorForHeaderRendering | Gets or sets the colour the caption band's gradient ends with. |
ExpandCollapseCircleFillColor | Gets or sets the colour of the round body of the collapse button. |
ExpandCollapseUpDownArrowsFillColor | Gets or sets the colour of the double arrow on the collapse button, which points up while the control is expanded and down while it is collapsed. |
FooterBorderColor | Gets or sets the colour of the border drawn inside the footer band. |
FooterBorderThickness | Gets or sets the thickness of the border drawn inside the footer band. |
FooterCaptionFont | Gets or sets the font of the footer text. |
FooterCaptionHeight | Gets or sets the depth of the footer band – its height along the bottom or top, its width down the left or right. |
FooterGradientDrawingDirection | Gets or sets the direction in which the footer band's gradient runs. |
FooterText | Gets or sets the text shown in the footer band – a status line such as a count of items. |
FooterTextForeColor | Gets or sets the colour of the footer text. |
FooterTextStringFormat | Gets or sets how the footer text is aligned, wrapped and trimmed. |
HeaderBitmapTransparencyColor | Gets or sets the colour in HeaderImage that is made transparent, so that the caption's
gradient shows through the picture's background. |
HeaderBorderColor | Gets or sets the colour of the border drawn inside the caption band. |
HeaderBorderThickness | Gets or sets the thickness of the border drawn inside the caption band. |
HeaderCaptionFont | Gets or sets the font of the caption text. |
HeaderCaptionHeight | Gets or sets the depth of the caption band – its height when it runs along the top or bottom, its width when it runs down the left or right. |
HeaderContextMenu | Gets or sets the menu the context menu button opens when ContextMenuType is
ContextMenuType.ContextMenu. |
HeaderContextMenu | Gets or sets the menu the context menu button opens when ContextMenuType is
ContextMenuType.ContextMenu. |
HeaderContextMenuStrip | Gets or sets the menu the context menu button opens. |
HeaderFooterDrawingStyle | Gets or sets how the caption and footer bands are filled: a plain gradient, or an Office-style two-tone band. |
HeaderGradientDrawingDirection | Gets or sets the direction in which the caption band's gradient runs. |
HeaderIcon | Gets or sets the icon drawn at the start of the caption, before the text. |
HeaderImage | Gets or sets the picture drawn at the start of the caption, before the text, when an icon will not do. |
HeaderImageType | Gets or sets which picture, if any, is drawn at the start of the caption. |
HeaderLocation | Gets or sets which edge of the control the caption band runs along. |
HeaderText | Gets or sets the title shown in the caption band. |
HeaderTextForeColor | Gets or sets the colour of the caption text. |
HeaderTextStringFormat | Gets or sets how the caption text is aligned, wrapped and trimmed. |
ShouldDrawDropShadow | Gets or sets whether a soft shadow is drawn along the control's bottom and right edges, lifting the pane off the form. |
Size | Gets or sets the size of the control, including its caption, footer, border and drop shadow. |
StartColorForBackgroundRendering | Gets or sets the colour the client area's background gradient starts with – the area behind the hosted controls. |
StartColorForFooterRendering | Gets or sets the colour the footer band's gradient starts with. |
StartColorForHeaderRendering | Gets or sets the colour the caption band's gradient starts with. |
UseAntiAliasingAsHeaderCaptionTextRenderingHint | Gets or sets whether the caption text is drawn with plain anti-aliasing rather than grid-fitted anti-aliasing. |
UseCustomImageForContextMenuButton | Gets or sets whether the context menu button is drawn with a picture of your own instead of the built-in round button. |
| Methods | |
OnFontChanged | Raises the Control.FontChanged event, and passes the new font on to any caption font
that has not been set explicitly. |
OnPaint | Paints the client area's background gradient, raises the Control.Paint event, and
redraws the caption, footer and border. |
OnPaintBackground | Does nothing: the whole client area is painted in OnPaint, which avoids flicker. |
OnResize | Raises the Control.Resize event after redrawing the caption, footer and border for the
new size. |
PerformCollapseExpand | Collapses the control to its caption, as clicking the collapse button does. |
WndProc | Processes the window messages that size, paint and hit test the caption and footer, and turns
clicks on them into HeaderClicked, FooterClicked, a collapse or the
context menu. |
| Events | |
FooterClicked | Occurs when the footer band is clicked. |
HeaderClicked | Occurs when the caption band is clicked. |
HeaderContextMenuAboutToBeDisplayed | Occurs when the context menu button in the caption is clicked, just before the menu opens. |
Constructors
BinaryHeaderControl
Initialises a new BinaryHeaderControl with the
ColorScheme.Blue colour scheme, the caption across the top and the
collapse button showing.
Remarks
The caption and footer text are centred, on one line, and trimmed with an ellipsis when
they do not fit. Both caption fonts follow the control's Control.Font until you set
one.
Properties
AutoScroll
Gets whether the client area scrolls; it never does.
- Value
- Always
false.
Remarks
To scroll the pane's content, add a BinaryScrollablePanel to the control and put the
child controls on the panel. At run time the panel fills the client area and scrolls when its
content is larger.
See also
BackgroundGradientDrawingDirection
Gets or sets the direction in which the client area's background gradient runs.
- Value
- The default is
Vertical: fromStartColorForBackgroundRenderingat the top toEndColorForBackgroundRenderingat the bottom.
BorderColor
Gets or sets the colour of the border drawn round the whole control.
- Value
- The default comes from the
ColorScheme:RGB(128, 167, 225)for the defaultColorScheme.Bluescheme. - Designer category
- Color
Remarks
While ColorScheme is anything other than ColorScheme.None,
choosing a scheme and setting StartColorForHeaderRendering both overwrite this colour;
set it after them.
See also
BorderStyle
Gets the standard Windows border style, which is always BorderStyle.None.
- Value
- Always
BorderStyle.None.
Remarks
The control draws its own border; use BorderColor and BorderWidth
to change it.
BorderWidth
Gets or sets the thickness of the border drawn round the whole control.
- Value
- The thickness in pixels. The default is 2. Values of 1 or less are stored as 2.
Remarks
The border is part of the frame, so a thicker border makes the client area smaller. Unlike the band heights, this width is not scaled with the display.
See also
ColorScheme
Gets or sets the built-in palette the caption, footer, background, border and context menu button are drawn in.
- Value
- The default is
ColorScheme.Blue. - Default
Blue
Remarks
Choosing a scheme overwrites StartColorForHeaderRendering,
EndColorForHeaderRendering, the background and footer gradient colours,
BorderColor, ContextMenuEllipseColor and
ContextMenuArrowColor. ColorScheme.None leaves them as
they are: choose it when you set those colours yourself, and set it before them.
The scheme is passed on to every BinaryScrollablePanel the control hosts directly;
other child controls are left as they are.
Example
// A corporate palette of your own: switch the schemes off first, then set the colours.
ordersPane.ColorScheme = ColorScheme.None;
ordersPane.StartColorForHeaderRendering = Color.FromArgb(0, 84, 147);
ordersPane.EndColorForHeaderRendering = Color.FromArgb(96, 160, 214);
ordersPane.HeaderTextForeColor = Color.White;
ordersPane.BorderColor = Color.FromArgb(0, 84, 147);See also
ControlIsInExpandedState
Gets or sets whether the control is expanded, as opposed to collapsed to its caption.
- Value
truewhen expanded. The default istrue.
Remarks
Reading the property tells you the current state, whether the user collapsed the control with
the caption button or code called PerformCollapseExpand.
Setting it does not resize the control. It records the current height as the one an expand
returns to, and redraws the collapse button for the new state. To collapse the control from code,
call PerformCollapseExpand.
See also
DisplayRectangle
Gets the area available to the hosted controls, in client coordinates.
- Value
- The client area: the control less its caption, footer, border and drop shadow band.
Remarks
The caption, footer, border and shadow are all outside the client area, so docked and anchored children stop short of them with no margins of your own.
DrawBorderAround
Gets or sets which bands – the caption, the footer, both or neither – have a border drawn just inside their edges.
- Value
- The default is
DrawBorderAround.None. - Designer category
- Header and footer rendering
Remarks
The caption's border is drawn with HeaderBorderColor and
HeaderBorderThickness, the footer's with FooterBorderColor and
FooterBorderThickness. A footer border shows only while the footer is drawn.
DropShadowColor
Gets or sets the colour of the drop shadow.
- Value
- The default is
Color.Black. The colour's alpha component is ignored;DropShadowOpacitysets how strong the shadow is. - Designer category
- Appearance
Remarks
Used only while ShouldDrawDropShadow is true.
DropShadowDepth
Gets or sets how far the drop shadow reaches beyond the frame.
- Value
- The depth in logical pixels (1/96 inch), from 0 to 16. The default is 4. Negative values are stored as 0 and values above 16 as 16.
- Default
DropShadowPainter.DefaultDepth- Designer category
- Appearance
Remarks
The depth is scaled with the display. A depth of 0 draws no shadow and gives the band back
to the client area. Used only while ShouldDrawDropShadow is true.
See also
DropShadowOpacity
Gets or sets how dark the drop shadow is where it is strongest, next to the frame.
- Value
- From 0 (invisible) to 255 (solid
DropShadowColor). The default is 96. Values outside the range are clamped to it. - Default
DropShadowPainter.DefaultOpacity- Designer category
- Appearance
Remarks
Used only while ShouldDrawDropShadow is true.
See also
EnableCollapseExpandButton
Gets or sets whether the caption shows a round button that collapses the control to its caption and expands it again.
- Value
trueto show the collapse button. The default istrue.
Remarks
The collapse button and the context menu button share one place at the end of the caption, so
setting this property also sets EnableHeaderContextMenu to the opposite value.
Clicking the button sets the control's height to the caption's height (plus the drop shadow,
when one is drawn) and clicking it again restores the height it had. The control does not collapse
in the designer. The button is drawn, and answers clicks, only when HeaderLocation is
HeaderLocation.Top; its colours are
ExpandCollapseCircleFillColor and ExpandCollapseUpDownArrowsFillColor.
See also
EndColorForBackgroundRendering
Gets or sets the colour the client area's background gradient ends with.
- Value
- The default comes from the
ColorScheme:RGB(197, 221, 250)for the defaultColorScheme.Bluescheme, white for the others. - Designer category
- Color
See also
EndColorForHeaderRendering
Gets or sets the colour the caption band's gradient ends with.
- Value
- The default comes from the
ColorScheme:RGB(197, 221, 250)for the defaultColorScheme.Bluescheme, white for the others. - Designer category
- Header rendering
Remarks
Choosing a ColorScheme other than ColorScheme.None
overwrites this colour.
See also
ExpandCollapseCircleFillColor
Gets or sets the colour of the round body of the collapse button.
- Value
- The default is
SystemColors.Window.
Remarks
ColorScheme does not change this colour.
See also
ExpandCollapseUpDownArrowsFillColor
Gets or sets the colour of the double arrow on the collapse button, which points up while the control is expanded and down while it is collapsed.
- Value
- The default is
SystemColors.WindowText.
Remarks
ColorScheme does not change this colour.
See also
HeaderBitmapTransparencyColor
Gets or sets the colour in HeaderImage that is made transparent, so that the caption's
gradient shows through the picture's background.
- Value
- The default is
Color.Transparent. - Designer category
- Header rendering
Remarks
The colour is applied to the bitmap itself, when it is assigned and again when this colour changes, so set the colour first. Pixels made transparent stay transparent.
See also
HeaderBorderColor
Gets or sets the colour of the border drawn inside the caption band.
- Value
- The default is
Color.White. - Designer category
- Header rendering
Remarks
Used only while DrawBorderAround includes the caption. A light colour on a
darker gradient gives the band a raised look.
See also
HeaderBorderThickness
Gets or sets the thickness of the border drawn inside the caption band.
- Value
- The thickness in pixels. The default is 2.
- Designer category
- Header rendering
Remarks
Used only while DrawBorderAround includes the caption.
See also
HeaderCaptionFont
Gets or sets the font of the caption text.
- Value
- The default is the control's
Control.Font, which the caption keeps following until this property is set. Settingnullmakes it follow the control's font again. - Designer category
- Header rendering
Remarks
The caption band is made deep enough for one line of this font whatever
HeaderCaptionHeight says.
See also
HeaderCaptionHeight
Gets or sets the depth of the caption band – its height when it runs along the top or bottom, its width when it runs down the left or right.
- Value
- The depth in logical pixels (1/96 inch). The default is the system's window caption height,
CaptionHeight. Values below 20 are raised to 20. - Designer category
- Header rendering
Remarks
The value is scaled with the display, and the band is never drawn shallower than one line of
HeaderCaptionFont plus a small margin, so a large caption font makes the band deeper
whatever this property says.
The caption is part of the frame: a deeper caption makes the client area smaller and moves the docked children.
See also
HeaderGradientDrawingDirection
Gets or sets the direction in which the caption band's gradient runs.
- Value
- The default is
Vertical: from the start colour at the band's top edge to the end colour at its bottom edge. - Designer category
- Header rendering
Remarks
A band down the left or right is drawn as if it lay along the top and is then turned on
its side, gradient and all, so that its top edge faces outwards. The direction is not used in the
HeaderFooterDrawingStyle.OfficeStyle drawing style.
See also
HeaderIcon
Gets or sets the icon drawn at the start of the caption, before the text.
- Value
- The default is
null: no icon. - Designer category
- Header rendering
Remarks
Setting this property also sets HeaderImageType to
HeaderImageType.Icon. The icon is drawn at its own size, reduced to
the caption's depth when it is larger, and the text starts after it.
See also
HeaderImage
Gets or sets the picture drawn at the start of the caption, before the text, when an icon will not do.
- Value
- The default is
null: no picture. - Designer category
- Header rendering
Remarks
Setting this property also sets HeaderImageType to
HeaderImageType.Bitmap. The picture is drawn at its own size, reduced
to the caption's depth when it is larger.
The bitmap you assign is changed in place: the pixels of
HeaderBitmapTransparencyColor are made transparent in it. Assign a copy if the original is
used elsewhere. The caption is not redrawn by this setter; it shows the picture at its next repaint.
Example
var picture = new Bitmap("Images\\calendar-16.bmp");
calendarPane.HeaderBitmapTransparencyColor = Color.Magenta; // the bitmap's background colour
calendarPane.HeaderImage = picture;
calendarPane.HeaderText = "Calendar";See also
HeaderImageType
Gets or sets which picture, if any, is drawn at the start of the caption.
- Value
- The default is
HeaderImageType.Icon. - Designer category
- Header rendering
Remarks
Setting HeaderIcon or HeaderImage sets this property to match, so
set it yourself only to switch between the two, or to
HeaderImageType.None to hide the picture without discarding it.
Nothing is drawn when the chosen picture is null.
HeaderLocation
Gets or sets which edge of the control the caption band runs along.
- Value
- The default is
HeaderLocation.Top. - Designer category
- Header rendering
Remarks
The footer, when DrawFooter is on, runs along the opposite edge. On the left and
right the caption and the footer are drawn turned on their side.
With HeaderLocation.Bottom no footer is drawn, and the collapse
button is drawn only with HeaderLocation.Top.
HeaderText
Gets or sets the title shown in the caption band.
- Value
- The default is
"Header text!". - Designer category
- Header rendering
Remarks
The text is drawn on one line in HeaderCaptionFont and
HeaderTextForeColor, centred by default and trimmed with an ellipsis when it is too long
(see HeaderTextStringFormat). Room is left for the icon and for the context menu button.
Use an empty string for a caption with no title; null stops the caption from
being drawn properly.
See also
HeaderTextForeColor
Gets or sets the colour of the caption text.
- Value
- The default is
SystemColors.ActiveCaption. - Designer category
- Header rendering
Remarks
ColorScheme does not change this colour, so pick one that reads well on the
scheme's caption gradient.
See also
HeaderTextStringFormat
Gets or sets how the caption text is aligned, wrapped and trimmed.
- Value
- The default centres the text both ways, keeps it on one line and trims it with an ellipsis
(
EllipsisCharacter).
Remarks
This property is not shown in the Properties window and is not saved by the designer; set
it in code. You can also change the existing object, for example its
StringFormat.Alignment, and then call Control.Refresh.
Example
// Left-align the caption, Outlook style.
ordersPane.HeaderTextStringFormat.Alignment = StringAlignment.Near;
ordersPane.Refresh();See also
ShouldDrawDropShadow
Gets or sets whether a soft shadow is drawn along the control's bottom and right edges, lifting the pane off the form.
- Value
trueto draw the shadow. The default isfalse.- Default
false- Designer category
- Appearance
Remarks
A control cannot paint outside its own bounds, so the shadow is drawn inside them: a band
DropShadowDepth deep along the bottom and right is given to the shadow, and the frame,
caption and client area shrink by that much. Turning the shadow on therefore moves anything docked or
anchored to those edges. The part of the band the shadow does not cover is painted in the nearest
opaque parent's Control.BackColor.
Example
notesPane.ShouldDrawDropShadow = true;
notesPane.DropShadowDepth = 6;
notesPane.DropShadowOpacity = 120;
notesPane.DropShadowColor = Color.FromArgb(40, 40, 60);See also
Size
Gets or sets the size of the control, including its caption, footer, border and drop shadow.
- Value
- The size in pixels, as for
Size.
Remarks
The first size assigned through this property while the control is expanded is recorded as
the height an expand returns to. Assigning it through a Control reference sets the size
without recording it.
StartColorForBackgroundRendering
Gets or sets the colour the client area's background gradient starts with – the area behind the hosted controls.
- Value
- The default comes from the
ColorScheme:RGB(128, 167, 225)for the defaultColorScheme.Bluescheme. - Designer category
- Color
Remarks
The gradient runs to EndColorForBackgroundRendering in the direction
BackgroundGradientDrawingDirection gives. The control paints this gradient instead of
Control.BackColor. Choosing a ColorScheme other than
ColorScheme.None overwrites the colour.
See also
StartColorForHeaderRendering
Gets or sets the colour the caption band's gradient starts with.
- Value
- The default comes from the
ColorScheme:RGB(128, 167, 225)for the defaultColorScheme.Bluescheme. - Designer category
- Header rendering
Remarks
The gradient runs from this colour to EndColorForHeaderRendering in the direction
HeaderGradientDrawingDirection gives. In the
HeaderFooterDrawingStyle.OfficeStyle drawing style both colours are
blended into a two-tone band instead, and this colour also outlines it.
While ColorScheme is anything other than
ColorScheme.None, setting this colour also sets
BorderColor to it, and choosing a scheme later overwrites it.
See also
UseAntiAliasingAsHeaderCaptionTextRenderingHint
Gets or sets whether the caption text is drawn with plain anti-aliasing rather than grid-fitted anti-aliasing.
- Value
trueforAntiAlias;falseforAntiAliasGridFit. The default isfalse.- Designer category
- Header and Footer rendering
Remarks
Plain anti-aliasing gives softer, slightly wider text that some prefer for large or bold caption fonts. The setting applies to the caption only; the footer text uses the system's default rendering.
Methods
OnFontChanged
Raises the Control.FontChanged event, and passes the new font on to any caption font
that has not been set explicitly.
Parameters
e- The data for the event.
Remarks
The caption and footer fonts follow Control.Font – whether it is set in code, in
the designer or inherited from the parent – until HeaderCaptionFont or
FooterCaptionFont is set. Set either to null to make it follow the
control's font again. The bands grow when needed to fit one line of the new font.
An override should call the base method so that the caption keeps following the font.
OnPaint
Paints the client area's background gradient, raises the Control.Paint event, and
redraws the caption, footer and border.
Parameters
e- The data for the event.
Remarks
The background runs from StartColorForBackgroundRendering to
EndColorForBackgroundRendering. A Control.Paint handler draws on top of
it. Nothing is painted while the control has no width or height.
OnPaintBackground
Does nothing: the whole client area is painted in OnPaint, which avoids flicker.
Parameters
pevent- The data for the event; not used.
OnResize
Raises the Control.Resize event after redrawing the caption, footer and border for the
new size.
Parameters
e- The data for the event.
Remarks
An override should call the base method, or the bands are not redrawn when the control is resized.
PerformCollapseExpand
Collapses the control to its caption, as clicking the collapse button does.
Parameters
collapsetrueto collapse the control;falseto expand it to the height it had before it collapsed.
Remarks
Collapsing records the current height and sets the height to the caption's depth (plus the drop shadow, when one is drawn). Expanding – from code or by a click on the collapse button – restores the recorded height. Asking for the state the control is already in changes nothing.
The method works whether or not EnableCollapseExpandButton is on, and also in the
designer. Collapsing suits a caption along the top: the control always shrinks upwards from the
bottom edge.
Example
// Keep the search pane folded away until it is needed.
searchPane.PerformCollapseExpand(true);
// ... later, open it again at the height it had.
searchPane.PerformCollapseExpand(false);See also
WndProc
Processes the window messages that size, paint and hit test the caption and footer, and turns
clicks on them into HeaderClicked, FooterClicked, a collapse or the
context menu.
Parameters
theWindowMessage- The window message to process.
Remarks
An override must call the base method for every message, or the caption, the footer and their clicks stop working.
Events
HeaderClicked
Occurs when the caption band is clicked.
Remarks
The event is raised when the left mouse button is released over the caption, anywhere except on its collapse or context menu button: a click on that button collapses the control or opens the menu instead.
Example
tasksPane.HeaderClicked += (sender, e) => tasksPane.PerformCollapseExpand(true);