Products Technologies Demo Docs Blog Support Company

Using the ResourceProvider to Customize the Ribbon MiniToolbar

This article explains how to add a custom RibbonButton to the Ribbon MiniToolbar using the ResourceProvider class.

Using the ResourceProvider to Customize the Ribbon MiniToolbar

The new TXTextControl.Windows.Forms.ResourceProvider class provides access to all high resolution images used in the built-in ribbon tabs and toolbars. Additionally, the ResourceProvider returns other built-in resources such as item descriptions and tooltips. This gives you access to a vector-based icon set with 800+ illustrations for our integrated button and ribbon bars. Depending on the selected DPI, the pixel-perfect bitmap in the requested size and resolution is returned for all various ribbon tabs and groups.

This way, you can use all TX Text Control resources in other user interface elements (such as the mini toolbar) to provide a consistent user experience.

The following code is used to create a new ribbon group with a button in the mini toolbar which is part of TX Text Control. A print button is inserted that prints the current document.

// default value
float m_DPI = 96;

public Form1()
{
    InitializeComponent();
    // use the system DPI
    m_DPI = CreateGraphics().DpiX;
}

private void textControl1_TextMiniToolbarInitialized(object sender,
  TXTextControl.MiniToolbarInitializedEventArgs e)
{
    // add separators to all groups
    foreach (RibbonGroup group in e.MiniToolbar.RibbonGroups)
    {
        group.ShowSeperator = true;
    }

    // create a new group
    RibbonGroup rgPrint = new RibbonGroup()
    {
        ShowSeperator = false
    };

    // add new group to mini toolbar
    e.MiniToolbar.RibbonGroups.Add(rgPrint);

    // create new RibbonButton
    RibbonButton rbPrint = new RibbonButton()
    {
        // get the resources from the ResourceProvider
        SmallIcon = ResourceProvider.GetSmallIcon("TXITEM_Print", m_DPI),
        LargeIcon = ResourceProvider.GetLargeIcon("TXITEM_Print", m_DPI),
        Text = ResourceProvider.GetText("TXITEM_Print"),
        KeyTip = ResourceProvider.GetKeyTip("TXITEM_Print")
    };

    // set the tool tip
    rbPrint.ToolTip.Description = ResourceProvider.GetToolTipDescription("TXITEM_Print");
    rbPrint.ToolTip.Title = ResourceProvider.GetToolTipTitle("TXITEM_Print");

    // attached a click event
    rbPrint.Click += RbPrint_Click;

    // add a RibbonButton to the new group
    rgPrint.RibbonItems.Add(rbPrint);
}

private void RbPrint_Click(object sender, EventArgs e)
{
    textControl1.Print("MyDocument");
}

The TXTextControl.Windows.Forms.ResourceProvider.GetSmallIcon method accepts the string identifier of the requested resource and the second parameter defines the required resolution. In the Form1 constructor, the DpiX property of a created Graphics object returns the current system resolution.

This way, the ResourceProvider always returns a pixel-perfect image based on the current resolution.

Custom MiniToolbar

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.Windows.Forms.ResourceProvider Class
  • TXTextControl.Windows.Forms.ResourceProvider.GetSmallIcon Method

Windows Forms

Text Control combines the power of a reporting tool and an easy-to-use WYSIWYG word processor - fully programmable and embeddable in your Windows Forms application. TX Text Control .NET for Windows Forms is a royalty-free, fully programmable rich edit control that offers developers a broad range of word processing features in a reusable component for Visual Studio.

See Windows Forms products