Products Technologies Demo Docs Blog Support Company

Opening the Tab Dialog on Clicking a Tab Position in the RulerBar

This short sample shows how to open the tab dialog on clicking a tab position in the RulerBar.

Opening the Tab Dialog on Clicking a Tab Position in the RulerBar

We received an interesting feature request in our support department: The ability to open the tab dialog when a user clicks a tab position in the TXTextControl.RulerBar class.

User input drives our development and we listen to all user requests and requirements. Such requests are collected and considered for future releases of our products. But most features can be already implemented based on the flexible API and our support services help with these requirements. We help with code snippets and tailored sample applications for all your requests.

Our technical support is part of every subscription license and you can also upgrade your non-subscription licenses to benefit from this service.

If you would like to learn more about the subscription services, feel free to contact us.

Tab Positions

In order to trap the double-click event in the RulerBar, the position needs to be calculated. In the MouseDoubleClick event, the position related to the document is calculated based on the scroll location and zoom factor.

Then the click location is compared to all tab positions at the current input position. If a tab position matches the click position within a range of 100 twips, the dialog is opened.

private void rulerBar1_MouseDoubleClick(object sender, MouseEventArgs e)
{
    // calculate zoom factor
    float fZoomFactor = (float)textControl1.ZoomFactor / 100;

    // get the click location in the ruler bar
    int iClickLocation = (int)((e.X * iDpiX) + (textControl1.ScrollLocation.X * fZoomFactor));

    // loop through all tab positions
    foreach (int tabPosition in textControl1.Paragraphs.GetItem(
        textControl1.Selection.Start).Format.TabPositions)
    {
        // retrieve the exact location including zoom factor
        int iTabLocation = (int)((tabPosition + 
            textControl1.Sections.GetItem().Format.PageMargins.Left) * fZoomFactor);

        // if click location matches tab position
        // open the tab dialog
        if (iClickLocation >= iTabLocation - 50 && iClickLocation <= iTabLocation + 50)
        {
            textControl1.TabDialog(); // open dialog
            break;
        }
    }
}

You can download the full sample from our GitHub repository.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Also See

This post references the following in the documentation:

  • TXTextControl.RulerBar Class

GitHub

Download and Fork This Sample on GitHub

We proudly host our sample code on github.com/TextControl.

Please fork and contribute.

Download ZIP

Open on GitHub

Open in Visual Studio

Requirements for this sample

  • Visual Studio 2017 or better
  • TX Text Control .NET for Windows Forms (trial sufficient)

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

Related Post

ASP.NETWindows FormsTab Stops

Text to Table and Table to Text in TX Text Control and C#

TX Text Control provides powerful table features and also full access to text formatting which can be used to create tables from text and vice versa. This article shows how to convert text to…