0

パッケージにいくつかのツール ウィンドウがあり、ユーザーがツール ウィンドウで何らかのアクションを実行したときに、ドキュメント内の特定のポイントを表示したいと考えています。

私は次のコードを試しました:

// 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 コード エディターにフォーカスが移ってしまい、ツール ウィンドウから離れてしまいます。ユーザーがツール ウィンドウに入力していて、突然エディターにフォーカスが移動した場合、これは適切ではありません。

フォーカスを失わずにこれを行う別の方法はありますか?

4

1 に答える 1

2
// 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();
于 2011-05-07T14:18:29.673 に答える