Products Technologies Demo Docs Blog Support Company

Is the Current Input Position Currently Visible?

Determining whether the cursor is in the visible area of a TX Text Control instance requires converting twips to 1/100-inch units and comparing InputPosition.Location against ScrollLocation and control dimensions. The C# helper method IsInputPositionVisible encapsulates this logic.

Is the Current Input Position Currently Visible?

I just saw an interesting request in our support department. When our users open such support cases, our engineers immediately begin creating sample applications tailored to the user's requirements. Providing fast, customer-oriented, and satisfying technical support is one of our most important business targets. Feel free to test our support department when you are having any questions. We spend a lot of time and effort to provide this kind of support quality.

Anyway, back to this specific requirement. A user wanted to know whether the current input position is in the visible area of the TextControl instance on the form. Generally, this task is quite easy. You simply need to compare the current input position and the scroll position with the height of the control itself. The same, also, for the horizontal position.

What you need to care about is the conversion between the used unit twips and the 1/100 inch for the width and height of controls in .NET. The following function returns true, if the current input position is currently visible.

private bool IsInputPositionVisible()
{
    // get resolution to calculate convert twips 1/100 inch
    Graphics g = textControl1.CreateGraphics();
    int DPI = (int)(1440 / g.DpiX);

    // get input and scroll positions and convert to 1/100 inch
    int inputPosX  = (textControl1.InputPosition.Location.X / DPI);
    int inputPosY  = (textControl1.InputPosition.Location.Y / DPI);
    int scrollPosX = (textControl1.ScrollLocation.X / DPI);
    int scrollPosY = (textControl1.ScrollLocation.Y / DPI);

    // check whether input position is inside visible area
    return ((inputPosX > scrollPosX && inputPosX < scrollPosX + textControl1.Width) &&
            (inputPosY > scrollPosY && inputPosY < scrollPosY + textControl1.Height))
            ? true : false;
}

Do you have any challenges programming with TX Text Control? Feel free to contact our support department.

Stay in the loop!

Subscribe to the newsletter to receive the latest updates.

Related Posts

Windows FormsWPF.NET

Create a Table of Contents in Windows Forms using C#

This article explains how to create a table of contents in Windows Forms using the ribbon or programmatically. Creating a table of contents is required to organize large documents.


Windows FormsList.NET

Two Ways to Restart Numbered Lists in TX Text Control

In TX Text Control, numbered lists are continued by default and need to be reset when required. There is more than one way if you want to restart numbered lists in a document. In this article, two…


.NETSample

Paste Special: The Easy Way to Implement

TX Text Control version 15.0 introduced a ClipboardFormat parameter on the Paste method, enabling native Paste Special functionality. The GetClipboardFormats method returns all available clipboard…


.NETSampleSections

How to Remove All Section Breaks in a Document?

TX Text Control 15.0 adds per-section page column support alongside existing section breaks. To remove all section breaks programmatically, iterate through SectionCollection using…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

Batch printing multiple documents as a single print job using TX Text Control relies on a .NET PrintDocument with PrintPage and QueryPageSettings events. Each page is rendered individually via the…

Share on this blog post on: