2011-05-07 3 views
0

내 패키지에 일부 도구 창이 있습니다. 사용자가 도구 창에서 일부 작업을 수행 할 때 문서의 특정 지점을보기에 가져 오려고합니다.Visual Studio - 포커스를 잃지 않고 커서 이동

나는 다음과 같은 코드를 시도했다 :

// 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 코드 편집기에 포커스를 둡니다. 사용자가 내 도구 창에 입력하고 갑자기 포커스를 편집기로 옮기는 경우에는 좋지 않습니다.

포커스를 잃지 않고이 작업을 수행 할 수있는 다른 방법이 있습니까?

+2

포커스를 뒤로 이동하려고 했습니까? ActiveWindow를 코드 앞에 저장하고, 이후에 Activate() 메서드를 호출하십시오. –

+0

이것은 트릭을 만들었습니다. 왜 내가 그런 생각을하지 않았는지 모르겠다! 감사. –

답변

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(); 
관련 문제