Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding cursor location in a textbox in vb.net

Tags:

vb.net

textbox

How do you find the location of the little blinking cursor where the user can type, column and row? I couldn't find this anywhere.

like image 346
Cyclone Avatar asked Sep 10 '09 22:09

Cyclone


People also ask

How to set cursor position in TextBox in vb net?

To position the cursor at the beginning of the contents of a TextBox control, call the Select method and specify the selection start position of 0, and a selection length of 0.

How do you get the cursor position in a TextBox in HTML?

Syntax: // will give the current position of the cursor document. getElementById("id"). selectionStart; // will get the value of the text area let x= $('#text1').


1 Answers

If you mean WinForms, use the SeletionStart property to access the current position of the carret. Here is code to get the index, current line and current column.

int index = myTextBox.SelectionStart;
int currentLine = myTextBox.GetLineFromCharIndex(index);
int currentColumn = index - myTextBox.GetFirstCharIndexFromLine(currentLine);
like image 160
Patrik Svensson Avatar answered Oct 23 '22 06:10

Patrik Svensson