locked
How to capture words(or line) in the visual studio? RRS feed

  • Question

  • Hi,everyone
     
    I am developing an add-in(help tool) in visual studio 2010 using C#.

    I want to capture some words(a line) in the editor .

    How can i do it? Somebody says  TextSelection can do it, but how?

    Thanks for your help!

    Wednesday, October 27, 2010 7:02 AM

Answers

  • view.Caret.MoveTo(view.GetTextViewLineContainingBufferPosition(view.TextSnapshot.GetLineFromPosition(view.TextSnapshot.GetText().IndexOf(fn)).Start));
                    System.Windows.Forms.SendKeys.Send("{RIGHT}");
    • Marked as answer by vpoint2010 Thursday, October 28, 2010 9:14 AM
    Thursday, October 28, 2010 9:13 AM

All replies

  • view.Caret.MoveTo(view.GetTextViewLineContainingBufferPosition(view.TextSnapshot.GetLineFromPosition(view.TextSnapshot.GetText().IndexOf(fn)).Start));
                    System.Windows.Forms.SendKeys.Send("{RIGHT}");
    • Marked as answer by vpoint2010 Thursday, October 28, 2010 9:14 AM
    Thursday, October 28, 2010 9:13 AM
  • Hi Vpoint,

     

    I'm glad it is resolved.

    Here are some lines works on my side:

    To select a line, please try:

    TextSelection objSel  = (TextSelection)dte.ActiveDocument.Selection;

    objSel.SelectLine();

    To capture a string, could you please try:

    TextSelection objSel  = (TextSelection)dte.ActiveDocument.Selection;

    bool exist = objSel.FindText("XXX");

    Hope this can help.

     

    Best Regards,

    Ziwei Chen

     

    Friday, October 29, 2010 8:45 AM