Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: CURSOR
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 7-Feb-13 23:31pm
Edited 7-Feb-13 23:34pm
v2
Comments
Chris Reynolds (BNY) at 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

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
 
If you want to get the position of the cursor:
 
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:
Char c =textBox1.GetCharFromPosition(nousePosition );
 
If you want to get the selected text:
 
string selectedText = textBox1.SelectedText;
 
Etc...
 
Valery.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 544
2 Maciej Los 325
3 DamithSL 223
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 10 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100