How to Use a WinForms Accordion Control in Your .NET 6 Application
Tags: webdev, tutorial, dotnet, devops
Published: 2022-12-22 14:53:38

---
canonical_url: https://www.grapecity.com/blogs/how-to-use-winforms-accordion-control-in-your-net-6-application
description: Learn how to use a WinForms accordion control in your .NET 6 application. See more from ComponentOne today.
---

The ComponentOne 2022 v2 release introduced our new Accordion control for .NET 6 applications. An accordion UI allows you to organize content into collapsible panels. This control also fills the gap created by our legacy .NET 4.5.2 TopicBar and OutBar controls.

In this blog, we will learn more about our new WinForms Accordion control and how to use it as a replacement in .NET 6 for TopicBar and OutBar controls.

### Introduction to Accordion

The new Accordion control allows you to toggle between collapsing and expanding substantial amounts of content with texts, images, and other simple UI controls. It has a compact interface that allows the content to be organized in vertically stacked collapsible pages that can be set to expand in four different directions. It will enable you to expand a page and collapse all other pages, automatically organizing your UI and optimizing the use of screen real estate.

![](https://files.grapecity.com/gc-website-media/cl0im1lw/01-accordionwithlistviews.gif?width=258&height=338)

The Accordion control can expand in four different directions, namely up, right, down, and left. This allows you to change the direction in which the control expands. For more information, see the [Expand Direction](https://www.grapecity.com/componentone/docs/win/online-accordion/expanddirection.html).

You can find the control in the new [C1.Win.Accordion](https://www.nuget.org/packages/C1.Win.Accordion/6.0.20222.576-beta) NuGet package.

Now that we know what the Accordion is and how it looks let us look at how to create the control and replace C1TopicBar and C1OutBar.

### Working with Accordion

Accordion is a panel with items organized as stacked pages called **Accordion Pages**. Each page in Accordion comprises a **page header** and an expandable-collapsible **content area**. The page header contains a header text with expand/collapse icon, and the content area provides a placeholder to hold different controls.

 It has a user-friendly UI allowing you to easily expand or collapse the pages using the expand/collapse icon. Accordion provided you the ability to either allow only a single page to be expanded or multiple pages. You can also restrict collapsing so that at least one page is always open.

The following image shows an Accordion with an Accordion page that has a List box in its content area.

![](https://files.grapecity.com/gc-website-media/lwqjgonx/02-accordion.png?width=500&height=311.46179401993356)

#### **Creating C1Accordion**

Accordion provides rich design-time features, including smart tags and a collection editor to add, remove and edit Accordion pages in the designer.

You can quickly and easily add multiple pages to the accordion from the smart-tag and set each header text. To add content to each page, use the following code where _myChildControl_ represents the content control, such as a ListView:

```
c1Accordion1.Pages[0].Content.Controls.Add(myChildControl);
```

For more details on getting started, check out our [Accordion quick start](https://www.grapecity.com/componentone/docs/win/online-accordion/quickstart.html).

#### **Replacing C1TopicBar**

In C1TopicBar, each page contains links stacked vertically; each link can be clicked and used to perform an operation. We can create a similar UI by using the Accordion.

First, we need to allow expanding and collapsing of all Accordion Pages by setting the AllowExpandMany and AllowCollapseAll properties of the Accordion to true.

```
    c1Accordion1.AllowExpandMany = true;
    c1Accordion1.AllowCollapseAll = true;
```

Then to show links in our Accordion Pages, we will use the LinkLabel control in this sample. Now for every link that we add to the accordion page, we will set the following properties to make the link similar to a topic link:

```
    label.Dock = DockStyle.Top;
    label.TextAlign = ContentAlignment.MiddleLeft;
    label.BackColor = c1Accordion1.Styles.Pages.Default.BackColor;
    label.ForeColor = label.LinkColor = c1Accordion1.Styles.Pages.Default.ForeColor;
    label.LinkBehavior = LinkBehavior.HoverUnderline;
```

And to get notified when a link is clicked, we can use the LinkClicked event of the LinkLabel.

```
    label.LinkClicked += Label_LinkClicked;
```

After adding a few links to the Accordion Page, it will look like the following:

![](https://files.grapecity.com/gc-website-media/mwnhfr2y/03-accordion.png?width=256&height=357)

You can download and refer to the blog sample at the link below. You can also perform further customizations as per your requirements.

#### **Replacing C1OutBar**

In C1OutBar, a page contains a toolbar, or it can contain other controls. Since C1Toolbar has already been migrated to .NET 6, we can create a UI similar to C1OutBar with Accordion and C1Toolbar.

First, to create a page with the toolbar, we can just create an Accordion Page and add a C1Toolbar to its content area. If we want to add arbitrary controls, then we can also add that to the content area of the Accordion page, just like you would do on a page of C1OutBar.

After adding the content to the Accordion, we would get something like the image below:

![](https://files.grapecity.com/gc-website-media/gaopjehe/04-accordion.png?width=254&height=336)

You can download and refer to the blog [sample](https://files.grapecity.com/gc-website-media/jvvf12ci/c1accordion_introduction.zip).

You can also perform further customizations as per your requirements. We hope you like the new control and find it easy to use in your application. You can refer to the Accordion documentation [here](https://www.grapecity.com/componentone/docs/win/online-accordion/overview.html) and the product sample [here](https://github.com/GrapeCity/ComponentOne-WinForms-Samples/tree/master/Core/Accordion/CS).