How do I get all of the code from a CodeWindow without losing the current TextSelection text? The technique is simple.
The Text Editor in the Visual Studio .NET IDE has Visible Code Windows. Behind each code window is an Edit Buffer. The visible code can be manipulated by using the TextSelection object. However, the Edit Buffer (hidden copy of the code window contents) can be selected, etc., behind the scenes, without disturbing the selection in the visible window, by the use of the EditPoint objects. When the user selects a block of code in the window, that code can be referenced with the following code.
| Dim ts As TextSelection = _ appObj.ActiveDocument.Selection ts.SelectAll() Dim s As String = ts.Text |
| Dim ts As TextSelection = oVB.ActiveDocument.Selection ' grab the code of the whole window, without destroying ' the selected text in the ts object Dim ep As EditPoint = ts.ActivePoint.CreateEditPoint ep.StartOfDocument() Dim bp As EditPoint = ts.ActivePoint.CreateEditPoint bp.EndOfDocument() Dim sAll As String = ep.GetLines(1, bp.Line) |