我的包中有一些工具窗口,当用户在工具窗口中执行某些操作时,我想将文档中的特定点显示在视图中。
我试过以下代码:
// Perform selection
TextSelection selection = activeDocument.Selection as TextSelection;
selection.MoveToAbsoluteOffset(offset, false);
// Show the currently selected line at the top of the editor if possible
TextPoint tp = (TextPoint)selection.TopPoint;
tp.TryToShow(vsPaneShowHow.vsPaneShowTop, null);
它做了我想做的事,但不幸的是,它把焦点放在了 Visual Studio 代码编辑器上,把它从我的工具窗口中拿走了。如果用户在我的工具窗口中键入并且它突然将焦点转移到编辑器,这并不好。
有没有另一种方法可以做到这一点而不会失去焦点?