Products Technologies Demo Docs Blog Support Company

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…

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

In an older sample, I showed how to implement a paste special functionality by accessing the clipboard directly using .NET functionality. In version 15.0, we implemented this functionality…


.NETSampleSections

How to Remove All Section Breaks in a Document?

With version 14.0, we introduced document section breaks that allow you to have different page formats in the same document. Version 15.0 implements page columns that can be adjusted section-wise.…


.NETPrintingSample

Batch Printing: How to Print Documents in One Print Job

A typical requirement when printing loads of documents is managing the print jobs. A group of separate documents might be subsumed in a single print job. We just published a new sample in our…