# Toolbars and Mini Toolbars

> Configure the Windows Forms ButtonBar and enable TextMiniToolbar and ObjectMiniToolbar with ShowMiniToolbar, then add ribbon groups or hide them on opening.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for Windows Forms > Document Editor > Ribbon and UI > Toolbars and Mini Toolbars
- **2999 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/toolbars/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/toolbars/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/toolbars/llms-full.txt

---

Not every editor needs a ribbon. The `ButtonBar` is a single tool bar with the most used font and paragraph commands, and the mini toolbars are small pop-up versions of the ribbon that appear next to the text a user selects or right-clicks. Both work with a `TextControl` in a Windows Forms application; the sections below show how to choose the buttons of the button bar, turn the mini toolbars on and add commands of your own to them.

[Add Rulers, Toolbars, and a Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/getting-started/document-editor/rulers-toolbars/llms-full.txt) adds the button bar to a form step by step.

### The Button Bar

The [ButtonBar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/llms-full.txt) in the `TXTextControl` namespace shows and sets the font and paragraph attributes of the connected editor: font name and size, bold, italic and underline, alignment, lists, indents, styles and zoom. It is connected through [TextControl.ButtonBar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/buttonbar-property/llms-full.txt), which the smart tag's **Arrange Controls Automatically** sets. Unlike the ribbon, it is part of every edition, Express included.

![A Windows Forms form in the designer with a button bar, a horizontal and a vertical ruler, a TextControl and a status bar.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/designer-bars-rulers.f80b7136.webp)

#### Choose and Order the Buttons

The buttons are values of the `TXTextControl.Button` enumeration, such as `FontBoldButton` and `FontItalicButton`, which the reference page of `ButtonPositions` lists. These members decide which buttons the bar shows and how:

| Member | Effect |
|---|---|
| [ButtonPositions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/buttonpositions-property/llms-full.txt) | The buttons in the order they are shown, up to 31 |
| [ButtonSeparators](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/buttonseparators-property/llms-full.txt) | For each position, whether a separator follows the button |
| [ButtonOffsets](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/buttonoffsets-property/llms-full.txt) | Additional distances between the buttons, in pixels |
| [ResetButtonPositions](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/resetbuttonpositions-method/llms-full.txt), [ResetButtonSeparators](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/resetbuttonseparators-method/llms-full.txt), [ResetButtonOffsets](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/resetbuttonoffsets-method/llms-full.txt) | Restore the default of each |

The Getting Started tutorial shows `ButtonPositions` and `ButtonSeparators` in code. The bar shows only buttons of the `Button` enumeration; commands of your own application belong in the ribbon, as described in [Custom Tabs and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/custom-tabs/llms-full.txt).

#### Appearance and Read-Only Mode

[ButtonStyle](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/buttonstyle-property/llms-full.txt) sets how the buttons are painted, and [BorderStyle](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/borderstyle-property/llms-full.txt) the border of the bar. With [ReadOnly](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/buttonbar/readonly-property/llms-full.txt) set to `true`, the bar keeps showing the attributes of the text at the input position, but users cannot change them with it:

```csharp
// Flat buttons, and no formatting through the button bar
buttonBar1.ButtonStyle = TXTextControl.ButtonStyle.FlatButtons;
buttonBar1.ReadOnly = true;
```

The color scheme of the bar is described in [Themes, Colors, and Icons](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/themes/llms-full.txt).

### Mini Toolbars

A [MiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbar/llms-full.txt) is a contextual tool bar with a few formatting groups. It opens at the mouse position when the user releases a mouse button, and the context decides which one appears:

- The [TextMiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textminitoolbar/llms-full.txt) appears for selected text, the text at the input position and a table. Its groups are font, styles and, in a table, table layout.
- The [ObjectMiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/objectminitoolbar/llms-full.txt) appears for a selected text frame, drawing frame or barcode frame, with borders, colors and alignment of that object. It opens only with the right mouse button.

![The text mini toolbar above a table with font name and size boxes, bold, italic, underline, colors, alignment, lists and the Styles gallery, together with the context menu.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/minitoolbar-text-selection.418ee184.webp)

#### Turn Them On

No mini toolbar is shown by default, so existing applications keep their behavior. [TextControl.ShowMiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/showminitoolbar-property/llms-full.txt) takes values of `MiniToolbarButton` that you combine with the bitwise or operator:

| Value | The mini toolbar appears |
|---|---|
| `None` | Never, the default |
| `LeftButton` | When the left mouse button is released and text is selected |
| `RightButton` | When the right mouse button is released |

```csharp
// Show mini toolbars for the left and the right mouse button
textControl1.ShowMiniToolbar = MiniToolbarButton.LeftButton | MiniToolbarButton.RightButton;
```

The context menu that opens with the right mouse button is described in [Context Menus](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/context-menus/llms-full.txt).

#### Change the Groups Once

The groups of a mini toolbar are ribbon groups: [MiniToolbar.RibbonGroups](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbar/ribbongroups-property/llms-full.txt) is the same kind of collection as the groups of a ribbon tab, and holds the same item classes. Right after a mini toolbar has been created, [TextMiniToolbarInitialized](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/textminitoolbarinitialized-event/llms-full.txt) or [ObjectMiniToolbarInitialized](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/objectminitoolbarinitialized-event/llms-full.txt) occurs, and that is where you change its structure.

The following handler removes the table group from the text mini toolbar and adds a group with a print button. Attach it in the constructor of the form with `textControl1.TextMiniToolbarInitialized += TextControl1_TextMiniToolbarInitialized;`:

```csharp
using TXTextControl;
using TXTextControl.Windows.Forms;
using TXTextControl.Windows.Forms.Ribbon;

private void TextControl1_TextMiniToolbarInitialized(object sender,
    MiniToolbarInitializedEventArgs e)
{
    // Remove the table layout group
    TextMiniToolbar miniToolbar = (TextMiniToolbar)e.MiniToolbar;
    RibbonGroup tableGroup = (RibbonGroup)miniToolbar.FindItem(
        TextMiniToolbar.RibbonItem.TXITEM_TableLayoutGroup);
    e.MiniToolbar.RibbonGroups.Remove(tableGroup);

    // Add a group with a print button
    string print = ResourceProvider.FileMenuItem.TXITEM_Print.ToString();
    RibbonGroup printGroup = new RibbonGroup() { ShowSeperator = false };
    RibbonButton printButton = new RibbonButton()
    {
        Text = ResourceProvider.GetText(print),
        LargeIcon = ResourceProvider.GetLargeIcon(print, this),
        DisplayMode = IconTextRelation.LargeIconLabeled
    };
    printButton.Click += (s, args) => textControl1.Print("My Document");
    printGroup.RibbonItems.Add(printButton);
    e.MiniToolbar.RibbonGroups.Add(printGroup);
}
```

The code works as follows:

- [MiniToolbarInitializedEventArgs.MiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbarinitializedeventargs/minitoolbar-property/llms-full.txt) is the new mini toolbar. You can change it, or assign a `MiniToolbar` of your own to replace it.
- [TextMiniToolbar.FindItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textminitoolbar/finditem-method/llms-full.txt) takes a value of [TextMiniToolbar.RibbonItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textminitoolbar/ribbonitem-enumeration/llms-full.txt), as `FindItem` of a ribbon tab does. `ObjectMiniToolbar` has its own [FindItem](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/objectminitoolbar/finditem-method/llms-full.txt) and `RibbonItem`.
- [ShowSeperator](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol-windows-forms-ribbon/ribbongroup/showseperator-property/llms-full.txt) turns off the separator after the last group. The `ResourceProvider` gives the new button the icon and text of the built-in print command, as described in [Custom Tabs and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/custom-tabs/llms-full.txt).

![A Windows Forms ribbon application with the text mini toolbar showing an added Print button and its tool tip above the context menu.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/minitoolbar-print-button.d6d5782f.webp)

#### Decide Each Time It Opens

[MiniToolbarOpening](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/minitoolbaropening-event/llms-full.txt) occurs every time a mini toolbar is about to open. Use it to show or hide groups for the current context, not to add them:

- [MiniToolbarContext](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbaropeningeventargs/minitoolbarcontext-property/llms-full.txt) says where the user clicked, as a combination of [ContextMenuLocation](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/contextmenulocation/enumeration/llms-full.txt) values such as `TextSelection`, `Table` or `SelectedFrame`.
- [MiniToolbar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbaropeningeventargs/minitoolbar-property/llms-full.txt) is the mini toolbar that opens; assign another one to show it instead. [Location](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/minitoolbaropeningeventargs/location-property/llms-full.txt) is its position in screen coordinates.
- The event arguments derive from `CancelEventArgs`: set `Cancel` to `true` and no mini toolbar opens.

```csharp
private void TextControl1_MiniToolbarOpening(object sender, MiniToolbarOpeningEventArgs e)
{
    // No mini toolbar for selected frames
    if ((e.MiniToolbarContext & ContextMenuLocation.SelectedFrame) != 0)
    {
        e.Cancel = true;
    }
}
```

The Howto sample *MiniToolbar*, installed in *%USERPROFILE%\\Documents\\TX Text Control 34.0.NET for Windows Forms\\CSharp\\Howto\\MiniToolbar*, adds an **Edit Hyperlink** group that its `MiniToolbarOpening` handler shows only when the user right-clicks a hyperlink:

![The text mini toolbar with an added Edit Hyperlink group, opened for a hyperlink in a table.](https://docs.textcontrol.com/assets/img/tx-text-control-dotnet-winforms/minitoolbar-hyperlink-group.754effa2.webp)

### Next Steps

- [Rulers and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/rulers-status-bar/llms-full.txt): the other bars around the editor.
- [Context Menus](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/context-menus/llms-full.txt): the menu that opens with the right mouse button.
- [Custom Tabs and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/custom-tabs/llms-full.txt): the ribbon classes the mini toolbar groups are made of.
- The blog article [Using the ResourceProvider to Customize the Ribbon MiniToolbar](https://www.textcontrol.com/blog/2019/07/10/using-the-resourceprovider-to-customize-the-ribbon-minitoolbar/): the print button example with icons for the current resolution.

---

## Nearby

- **Previous:** [Custom Tabs and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/custom-tabs/llms-full.txt)
- **Next:** [Rulers and Status Bar](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/document-editor/ribbon-ui/rulers-status-bar/llms-full.txt)
