Click here to Skip to main content
15,911,711 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a text box with some string in it. when i double click inside it I want to get the cursor at that particular position .how can i do this.?
Posted
Updated 7-Feb-13 22:34pm
v2
Comments
Chris Reynolds (UK) 8-Feb-13 6:49am    
If you mean the caret which is the little I shaped bar that shows your position in the text box then you can use SelectionStart and SelectionLength but the double clicking will mean that a whole word is selected and so the caret is moved to the end of the word. Can you explain more clearly why you want the information?

1 solution

Hello,

If you want to get the position of the cursor:

C#
private void textBox1_DoubleClick(object sender, EventArgs e)
{
    MouseEventArgs mouseEventAgrs = (MouseEventArgs) e;
    Point nousePosition = mouseEventAgrs.Location;
}


If you want to get the character at the position where you double-clicked:

Add:
C#
Char c =textBox1.GetCharFromPosition(nousePosition );


If you want to get the selected text:

C#
string selectedText = textBox1.SelectedText;


Etc...

Valery.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900