繁体   English   中英

Visual Studio - 移动光标而不会失去焦点

[英]Visual Studio - Move cursor without losing focus

我的包中有一些工具窗口,当用户在工具窗口中执行某些操作时,我想将文档中的特定点放入视图中。

我试过以下代码:

// 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代码编辑器上,从我的工具窗口中取出它。 如果用户在我的工具窗口中输入并且它突然将焦点移动到编辑器,则这不好。

有没有其他方法可以做到这一点而不会失去焦点?

// Store active window before selecting
Window activeWindow = applicationObject.ActiveWindow;

// 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);

// Restore focus to active window
activeWindow.Activate();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM