Another TextBox Question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to know the position of the cursor inside the TextBox. How Can I do that



Thanks in advantage...
 
textBox.SelectionStart

-vJ

Can
I do that?


TextBox.SelectionStart returns start position of the selection. But the
caret (cursor position inside the textbox) may be outside the selection.
If you interested in finding out where the caret (cursor) is, then you may
need to use the extern function in user32.dll called GetCaretPos.

Here is the msdn help site on GetCaretPos.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI
/WindowsUserInterface/Resources/Carets/CaretReference/CaretFunctions/GetCare
tPos.asp

Sample code. (Here is what i think it would look like, i have not tried
this code out.)

using System.Runtime.InteropServices; // you have to include this to use
the extern method.

class myClass
{
[DllImport("user32.dll")]
public static extern bool GetCaretPos(ref Point pt);

public void MyMethod ()
{
Point pt = new Point(0, 0);

if (GetCaretPos(ref pt))
{
MessageBox.Show("x = " + pt.X.ToString() + " y = " +
pt.Y.ToString());
}


}
}


Hope this helps.


--
Adrian Mascarenhas, Developer Division

This posting is provided "AS IS" with no warranties, and confers no rights.

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
Back
Top