4
我有一個運行的宏,它向我的文檔寫入版權標題。當前在寫入標題時,光標留在標題的末尾。在Visual Studio中運行宏時獲取光標位置
我想要做的是捕獲當前位置,寫入標題,然後將光標返回到原始位置。
有誰知道這是如何實現的?
我有一個運行的宏,它向我的文檔寫入版權標題。當前在寫入標題時,光標留在標題的末尾。在Visual Studio中運行宏時獲取光標位置
我想要做的是捕獲當前位置,寫入標題,然後將光標返回到原始位置。
有誰知道這是如何實現的?
我想我已經明白了。
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)
這是所有嵌套在我寫的自動爲每個代碼文件添加版權標題的宏。