【发布时间】:2011-03-12 14:45:19
【问题描述】:
我运行了一个宏,它将版权标题写入我的文档。目前在写header的时候,光标停留在header的末尾。
我想做的是捕获当前位置,写入标题,然后将光标返回到原始位置。
有谁知道如何做到这一点?
【问题讨论】:
标签: visual-studio macros
我运行了一个宏,它将版权标题写入我的文档。目前在写header的时候,光标停留在header的末尾。
我想做的是捕获当前位置,写入标题,然后将光标返回到原始位置。
有谁知道如何做到这一点?
【问题讨论】:
标签: visual-studio macros
我想我明白了。
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)
这全部嵌套在我编写的宏中,用于自动为每个代码文件添加版权标题。
【讨论】: