HypernovaDesktop Components · docs
Binarymission
WinForms › Header Control

Header Control

.NET Framework 4.8.NET 6 / 8 / 10v3.0.0WinForms

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.

11public types
120public members
1namespaces

Assembly

AssemblyBinarymission.WinForms.Controls.HeaderControl.dll
Root namespaceBinarymission.WinForms.Controls.NavigationControls
Target frameworks.NET Framework 4.8, .NET 6 / 8 / 10

Overview

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. HeaderLocation puts 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. ColorScheme sets the caption, footer, background and border colours in one go. Choose ColorScheme.None to keep colours of your own.
  • No scrolling of its own. AutoScroll is always false. Put a BinaryScrollablePanel inside 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.

Getting started

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";
    }
}

API reference

Binarymission.WinForms.Controls.NavigationControls

class BinaryHeaderControlA 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.
class BinaryHeaderControlActionListSupplies the smart tag panel shown for a BinaryHeaderControl on the Windows Forms designer surface: the colour scheme, drawing style, caption and footer text, header location and the choice between the collapse button and the context menu.
class BinaryScrollablePanelA scrolling, gradient-filled panel that fills the client area of a BinaryHeaderControl, for pane content that can be longer than the pane.
enum ColorSchemeSpecifies the built-in palette a BinaryHeaderControl or a BinaryScrollablePanel is drawn in.
enum ContextMenuButtonImageTypeSpecifies what a BinaryHeaderControl draws as its context menu button.
enum ContextMenuTypeSpecifies which of two menus the context menu button of a BinaryHeaderControl opens.
enum DrawBorderAroundSpecifies which bands of a BinaryHeaderControl have a border drawn just inside their edges.
delegate HeaderContextMenuAboutToBeDisplayedHandlerRepresents the method that handles HeaderContextMenuAboutToBeDisplayed, and can stop the header's context menu from opening.
enum HeaderFooterDrawingStyleSpecifies how the caption and footer bands of a BinaryHeaderControl are filled.
enum HeaderImageTypeSpecifies which picture, if any, a BinaryHeaderControl draws at the start of its caption.
enum HeaderLocationSpecifies which edge of a BinaryHeaderControl its caption band runs along.