c# - Find text under caret position -


i find caret position in application need know text (word) there @ current caret position.

how can text?

if using winforms application, , caret position mean caret position in textbox. thing this.

  • 1. attach event handlers keyup , mouseup events
  • 2. current textbox text , caret position
  • 3. pass function returns word under position
  •     private void textbox1_keyup(object sender, eventargs e)     {         getwordfromcaretposition(textbox1.text, textbox1.selectionstart);     }      private void textbox1_mouseup(object sender, eventargs e)     {         getwordfromcaretposition(textbox1.text, textbox1.selectionstart);     }      private string getwordfromcaretposition(string input, int position)     {         string word = string.empty;         //yet implemented.         return word;     } 

  • for wpf textbox caret position represented textbox1.caretindex
  • for wpf richtextbox see thread : wpf richtextbox - whole word @ current caret position
  • for windows phone 7 caret position represented textbox1.selectionstart. see thread if app windows phone app: selecting tapped-on word on single click in textbox

  • Comments

    Popular posts from this blog

    linux - Does gcc have any options to add version info in ELF binary file? -

    android - send complex objects as post php java -

    charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -