Skip to the guide
All guides

Add a task pane with groups of links

Use MxTaskPane to show groups of task links beside your content. Groups can expand, collapse and close, and an item click runs your code.

app Mordex Components 6.0.0checked reading 4 minutes

On this page

MxTaskPane is a side pane like the task pane of the Windows XP file explorer. It shows groups with a header. Each group holds items, and most items are links that run a task. The types are in the Mordex.Windows.TaskPane namespace.

A task pane with the groups File tasks, Edit tasks, Tools and Details
A task pane with the groups File tasks, Edit tasks, Tools and Details

Groups of tasks and a details group

Add the pane to a form

Create the pane and dock it at the side. Give it an image list for the item icons and set ImageSize to the size of those icons.

C#
using System.Drawing;
using System.Windows.Forms;
using Mordex.Windows.TaskPane;

MxTaskPane pane = new MxTaskPane
{
    Dock = DockStyle.Left,
    Width = 270,
    ImageList = icons,
    ImageSize = new Size(16, 16)
};
Controls.Add(pane);

In Visual Studio you can drop MxTaskPane on a form and add groups with its Groups Designer.

Add groups and items

A TaskPaneGroup takes its header text in the constructor. A TaskPaneItem takes a text and an image index. Add items to TaskPaneGroup.Items and groups to MxTaskPane.Groups.

C#
TaskPaneGroup file = new TaskPaneGroup("File tasks") { Expanded = true };
file.Items.Add(new TaskPaneItem("New document", 0) { ToolTipText = "New document" });
file.Items.Add(new TaskPaneItem("Open a folder", 1));
file.Items.Add(new TaskPaneItem("Save a copy", 2));
pane.Groups.Add(file);

TaskPaneGroup edit = new TaskPaneGroup("Edit tasks");
edit.Items.Add(new TaskPaneItem("Cut", 4));
edit.Items.Add(new TaskPaneItem("Copy", 5));
pane.Groups.Add(edit);

Key gives a group or an item a name, so you can find it with pane.Groups["key"] or group.Items["key"].

ItemType sets the kind of item.

ValueWhat it shows
LinkButtonA link that the user can click. This is the default.
DescriptionPlain text, for example details about a file.
SeparatorA line between items.
Values of ItemType

Pass the type in the constructor. This group only shows information. SpecialGroup draws it in the special group style.

C#
TaskPaneGroup details = new TaskPaneGroup("Details") { SpecialGroup = true };
details.Items.Add(new TaskPaneItem("Quarterly report.docx", ItemType.Description));
details.Items.Add(new TaskPaneItem("Word document, 148 KB", ItemType.Description));
pane.Groups.Add(details);

Run a task when an item is clicked

ItemClick gives you the item in e.Item. Check ItemType so that you only act on links. TaskPaneItem.Group gives the group of the item.

C#
pane.ItemClick += (sender, e) =>
{
    TaskPaneItem item = e.Item;
    if (item.ItemType != ItemType.LinkButton)
    {
        return;
    }
    status.Text = "Run " + item.Text + " from " + item.Group.Text;
};

Each TaskPaneItem also has its own Click event. GroupClick runs when the user clicks a group header.

Expand, collapse and close groups

Expanded opens or closes a group in code. The user opens and closes a group with the button in its header.

C#
foreach (TaskPaneGroup group in pane.Groups)
{
    group.Expanded = false;
}

These group properties change what the user can do:

  • Expandable shows the expand button. Set it to false to keep the group open.
  • ShowCloseButton shows a close button on the group.

Effect on the pane sets the animation: Fade (the default), Scroll or None.

The pane raises events around these changes. GroupExpanding, GroupCollapsing and GroupClosing run first. Set e.Cancel to true to stop the change. GroupExpanded, GroupCollapsed and GroupClosed run after it.

C#
pane.GroupClosing += (sender, e) =>
{
    if (e.Group.SpecialGroup)
    {
        e.Cancel = true;
    }
};

Change the look

PropertyWhat it does
ShowGroupBorderDraws a border around each group.
ShowToolTipsShows the ToolTipText of groups and items.
KeepSelectionKeeps an item drawn as selected after the user clicks it.
ColumnsSets how many groups sit side by side. The default is 1.
Look and behavior properties of MxTaskPane

The pane follows the application theme. See Themes.

Put your own controls in a group

A group can hold controls in place of items. Add the group to the pane first, then set Container to true. The group then has a ContainerControl, which is a panel for your controls. ContainerHeight sets its height in pixels.

C#
TaskPaneGroup search = new TaskPaneGroup("Search");
pane.Groups.Add(search);
search.Container = true;
search.ContainerHeight = 60;

TextBox query = new TextBox { Dock = DockStyle.Top };
search.ContainerControl.Controls.Add(query);

A single TaskPaneItem can also be a container. It has its own Container, ContainerHeight and ContainerControl properties.