This sample shows how to manipulate the MiniToolbar in order to add contextual content groups.

Inspired by Microsoft Word, the new MiniToolbar is a small version of the full ribbon toolbar providing the most common formatting features. The MiniToolbar appears when text is selected or selected text is right-clicked.

This context sensitive toolbar is very handy for quick formatting tasks without moving the mouse back and forth from the selection to the full ribbon bar.

When right-clicking a selection or an object such as a table or text frame, contextual features are displayed in the MiniToolbar.

The TextControl.ShowMiniToolbar property can be used to control under which circumstances the toolbar should be shown. By default, the MiniToolbar is not shown and must be enabled programmatically to keep applications backwards compatible. In the TextControl.MiniToolbarOpening event, the MiniToolbar can be customized or replaced.

The sample adds a new group to the MiniToolbar to edit hyperlinks when the MiniToolbar is opened by clicking a hyperlink in a document. The following code creates a new RibbonGroup:

[C#]
private RibbonGroup CreateEditHyperlinkGroup() {
    RibbonGroup rgEditHyperlinkGroup = new RibbonGroup() { ShowSeperator = false };
    Bitmap bmpEditHyperLink = new Bitmap("edithyperlink.png");
    RibbonButton rbtnEditHyperlink = new RibbonButton() { Text = "Edit Hyperlink", LargeIcon = bmpEditHyperLink };
    rbtnEditHyperlink.Click += EditHyperlink_Click;

    rgEditHyperlinkGroup.RibbonItems.Add(rbtnEditHyperlink);

    return rgEditHyperlinkGroup;
}
[Visual Basic]
Private Function CreateEditHyperlinkGroup() As RibbonGroup
    Dim rgEditHyperlinkGroup As RibbonGroup = New RibbonGroup
    Dim bmpEditHyperLink As Bitmap = New Bitmap("edithyperlink.png")
    Dim rbtnEditHyperlink As New RibbonButton
    rbtnEditHyperlink.Text = "Edit Hyperlink"
    rbtnEditHyperlink.LargeIcon = bmpEditHyperLink

    AddHandler rbtnEditHyperlink.Click, AddressOf Me.EditHyperlink_Click
    rgEditHyperlinkGroup.RibbonItems.Add(rbtnEditHyperlink)
    Return rgEditHyperlinkGroup
End Function

This group is added in the TextControl.TextMiniToolbarInitialized event:

[C#]
private void textControl1_TextMiniToolbarInitialized(object sender, TXTextControl.MiniToolbarInitializedEventArgs e) {
    e.MiniToolbar.RibbonGroups.Add(CreateEditHyperlinkGroup());
}
[Visual Basic]
Private Sub textControl1_TextMiniToolbarInitialized(ByVal sender As Object, ByVal e As TXTextControl.MiniToolbarInitializedEventArgs) Handles TextControl1.TextMiniToolbarInitialized
    e.MiniToolbar.RibbonGroups.Add(CreateEditHyperlinkGroup())
End Sub

In the TextControl.MiniToolbarOpening event, contextual groups are hidden dynamically:

[C#]
private void textControl1_MiniToolbarOpening(object sender, TXTextControl.MiniToolbarOpeningEventArgs e) {
    if (e.MiniToolbar is TextMiniToolbar) {
        e.MiniToolbar.RibbonGroups[1].Visible = true;
        e.MiniToolbar.RibbonGroups[1].ShowSeperator =
        e.MiniToolbar.RibbonGroups[2].Visible =

        (e.MiniToolbarContext & ContextMenuLocation.TextField) == ContextMenuLocation.TextField &&
        textControl1.HypertextLinks.GetItem() != null;
    }
}
[Visual Basic]
Private Sub textControl1_MiniToolbarOpening(ByVal sender As Object, ByVal e As TXTextControl.MiniToolbarOpeningEventArgs) Handles TextControl1.MiniToolbarOpening

    If (TypeOf e.MiniToolbar Is TextMiniToolbar) Then
        e.MiniToolbar.RibbonGroups(1).Visible = True
        e.MiniToolbar.RibbonGroups(2).Visible = (((e.MiniToolbarContext And ContextMenuLocation.TextField) _
                    = ContextMenuLocation.TextField) _
                    AndAlso (Not (TextControl1.HypertextLinks.GetItem) Is Nothing))
        e.MiniToolbar.RibbonGroups(1).ShowSeperator = (((e.MiniToolbarContext And ContextMenuLocation.TextField) _
                    = ContextMenuLocation.TextField) _
                    AndAlso (Not (TextControl1.HypertextLinks.GetItem) Is Nothing))
    End If
End Sub

When right-clicking a hyperlink in the sample, the MiniToolbar is shown with the new contextual ribbon group: