Get cursor location when running a macro in visual Studio

I have a macro that I run that writes the copyright header to my document. Currently, when the title is written, the cursor remains at the end of the title.

What I would like to do is capture the current location, write down the title, and then return the cursor to the original location.

Does anyone know how to do this?

+4
source share
1 answer

I think I have.

Dim selection As TextSelection = DTE.ActiveDocument.Selection ''# store the original selection and cursor position Dim topPoint As TextPoint = selection.TopPoint Dim bottomPoint As TextPoint = selection.BottomPoint Dim lTopLine As Long = topPoint.Line Dim lTopColumn As Long = topPoint.LineCharOffset Dim lBottomLine As Long = bottomPoint.Line Dim lBottomColumn As Long = bottomPoint.LineCharOffset() Dim verticalOffset As Integer = 0 ''# do a bunch of stuff that adds text to the page ''# Restore cursor to previous position selection.MoveToLineAndOffset(lBottomLine + verticalOffset, lBottomColumn) selection.MoveToLineAndOffset(lTopLine + verticalOffset, lTopColumn, True) 

This is all nested in a macro that I wrote to automatically add a header for each code file.

+7
source

Source: https://habr.com/ru/post/1314906/


All Articles