Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Visual Studio-在不失去焦点的情况下移动光标_C#_Visual Studio_Vs Extensibility_Vspackage - Fatal编程技术网

C# Visual Studio-在不失去焦点的情况下移动光标

C# Visual Studio-在不失去焦点的情况下移动光标,c#,visual-studio,vs-extensibility,vspackage,C#,Visual Studio,Vs Extensibility,Vspackage,我的包中有一些工具窗口,当用户在工具窗口中执行某些操作时,我希望查看文档中的特定点 我尝试了以下代码: // Perform selection TextSelection selection = activeDocument.Selection as TextSelection; selection.MoveToAbsoluteOffset(offset, false); // Show the currently selected line at the top of the editor

我的包中有一些工具窗口,当用户在工具窗口中执行某些操作时,我希望查看文档中的特定点

我尝试了以下代码:

// 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);
它实现了我想要的功能,但不幸的是,它将焦点放在了VisualStudio代码编辑器上,将其从我的工具窗口中移除。如果用户在“我的工具”窗口中键入内容,并且它突然将焦点移动到编辑器,则这是不好的


有没有其他方法可以在不失去焦点的情况下做到这一点?

您是否尝试过将焦点移回原位?在代码之前存储ActiveWindow,在代码之后调用其Activate()方法。我不知道为什么我没有想到这一点!谢谢
// 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();