get current position in textbox

  • Thread starter Thread starter gie
  • Start date Start date
G

gie

hi dear,i want to get the current position of a cursor in textbox to
retrieves the textbox cursor position in screen coordinates.yours sincerely
Markus
 
Private Sub TextBox1_TextChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged

Dim inLetters As Integer
Dim i As Integer
Dim strC As String
Dim bPrev As Boolean

bPrev = False
For i = 1 To Len(TextBox1.Text)

inLetters = inLetters + 1

Next

TextBox2.Text = inLetters

End Sub
 
doesn't this show the length of text in a text box vs. the position of
the cursor...?
 
I'm not sure I understand the question, but if you are asking how to detect
the caret (narrow blinking vertical bar inside a text box) position, you
will need to P/Invoke GetCaretPos(). It returns caret position in client
coordinates. To convert it to screen coordinates use
Control.PointToScreen().

C#
using System.Runtime.InteropServices;

[DllImport("coredll")]
static extern bool GetCaretPos( out Point pt );

VB.NET:
Imports System.Runtime.InteropServices
<DllImport("coredll")> _
shared Function GetCaretPos( ByRef pt as Point ) as Boolean
End Function
 
Back
Top