gpt4 book ai didi

visual-studio - 在 Visual Studio 中运行宏时获取光标位置

转载 作者:行者123 更新时间:2023-12-05 00:06:27 26 4
gpt4 key购买 nike

我有一个我运行的宏,它将版权标题写入我的文档。当前写入标题时,光标会留在标题的末尾。

我希望能够做的是捕获当前位置,写入标题,然后将光标返回到原始位置。

有谁知道如何做到这一点?

最佳答案

我想我已经明白了。

        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)

这一切都嵌套在我编写的宏中,以自动向每个代码文件添加版权 header 。

关于visual-studio - 在 Visual Studio 中运行宏时获取光标位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3191512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com