If you use the CodeModel and FileCodeModel to manipulate your way through a project, How do you open a code window and move to a desired line in the code window?
Assuming that you know the name of the Solution, Project, and Code Window to open and have the line number that you want to move to, you can call the DisplayCodeSelection method, shown below, to perform the desired functionality. The calling sequence is shown below.
| Public Sub test() DisplayCodeSelection("NetCommander\NetCommander\CWindows.vb", 252) End Sub |
| Public Sub DisplayCodeSelection(ByVal rsWinName As String, _ ByVal riLine As Integer) ' Open the specified window, move to specified line ' and select the line. ' This method can be called by features such as search ' program, project browser, and track changes. ' rsWinName="SlnName\PrjName\modulename.vb" Dim s As String Try ' Activate the project explorer oVB.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate() ' select the desired code window in the explorer oVB.ActiveWindow.Object.GetItem(rsWinName). _ Select(vsUISelectionType.vsUISelectionTypeSelect) ' ask the IDE to open the code window oVB.ExecuteCommand("View.ViewCode") System.Windows.Forms.Application.DoEvents() ' create a TextSelection object so we can select the desired line Dim objTextDoc As TextSelection = _ oVB.ActiveDocument.Selection ' move to the top of the document objTextDoc.StartOfDocument() ' now, move to the desired line objTextDoc.MoveToLineAndOffset(riLine, 1, False) ' move down a line, causing the previous line to be highlighted objTextDoc.MoveToLineAndOffset(riLine + 1, 1, True) Catch ex As System.Exception End Try End Sub |