Products Technologies Demo Docs Blog Support Company

Set the Current Input Position on a Right Mouse Click

I just read a thread in our Support Forum that a customer was asking how to set the current input position, when the end-user clicks the right mouse button. I would like to take this opportunity to publish the simple solution here. We just need two things: the MouseDown event to check, if the end-user clicks the right mouse button and the InputPosition class to set the caret to that specific position. The returned coordinates from the MouseDown event can be passed to the InputPosition…

Set the Current Input Position on a Right Mouse Click

I just read a thread in our Support Forum that a customer was asking how to set the current input position, when the end-user clicks the right mouse button. I would like to take this opportunity to publish the simple solution here.

We just need two things: the MouseDown event to check, if the end-user clicks the right mouse button and the InputPosition class to set the caret to that specific position. The returned coordinates from the MouseDown event can be passed to the InputPosition constructor.

Imports System.Drawing

Dim DPI As Point

Private Sub Form1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
 DPI.X = e.Graphics.DpiX
 DPI.Y = e.Graphics.DpiY
End Sub

Private Function GetLocation(ByVal pt As Point) As Point
 Dim m_pt As New System.Drawing.Point
 Dim dpiX As Integer = DPI.X
 Dim dpiY As Integer = DPI.Y
 Dim offsetY As Integer = TextControl1.ScrollLocation.Y
 Dim offsetX As Integer = TextControl1.ScrollLocation.X

 m_pt = New Point(pt.X, pt.Y)
 m_pt.X = (m_pt.X * CInt((1440 / dpiX))) + offsetX
 m_pt.Y = (m_pt.Y * CInt((1440 / dpiY))) + offsetY

 Return m_pt
End Function

Private Sub TextControl1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextControl1.MouseDown
 If e.Button = MouseButtons.Right Then
  TextControl1.InputPosition = New TXTextControl.InputPosition(GetLocation(e.Location))
 End If
End Sub

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…