6
A
回答
7
我也對此感到沮喪。你在VSTO應用程序中使用對話框嗎?如果是這樣,我所做的是將事件添加到Windows窗體/對話框的關閉以激活Office應用程序如下(例如與Word,所以有可能在Excel中的差異):
//... VSTO Startup Event
WindowsForm form = new WindowsForm();
form.FormClosed += new FormClosedEventHandler(form_FormClosed);
form.Show();
void form_FormClosed(object sender, FormClosedEventArgs e)
{
this.Application.Activate();
this.Application.ActiveWindow.WindowState = Microsoft.Office.Interop.Word.WdWindowState.wdWindowStateNormal;
}
我發現這條線始終位於/返回true:
this.ActiveWindow.Active()
但這個工作得更好(全球bool變量 「AppActive」 跟蹤活動窗口):
//... VSTO Startup Event
this.Application.WindowDeactivate += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowDeactivateEventHandler(Application_WindowDeactivate);
this.Application.WindowActivate += new Microsoft.Office.Interop.Word.ApplicationEvents4_WindowActivateEventHandler(Application_WindowActivate);
void Application_WindowActivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
{
AppActive = true;
}
void Application_WindowDeactivate(Microsoft.Office.Interop.Word.Document Doc, Microsoft.Office.Interop.Word.Window Wn)
{
AppActive = false;
}
2
this.ActiveWindow.Activate()
是激活窗口的方法。
this.ActiveWindow.Active
是告訴你窗口狀態的屬性。
相關問題
- 1. c#:VSTO - > MS Office應用程序失去焦點?
- 2. 測試VSTO應用程序?
- 3. c#檢測應用程序的焦點丟失焦點
- 4. 在一個應用程序應用程序中設置焦點
- 5. Delphi應用程序丟失焦點
- 6. 焦點聽衆在panio應用程序
- 7. 將焦點設置Excel應用程序
- 8. 專注於Excel VSTO WPF應用程序
- 9. VSTO應用程序代碼分析
- 10. Java小應用程序閃爍焦點丟失和焦點已着色
- 11. 黑莓應用程序失去焦點,並導致應用程序凍結
- 12. 當應用程序失去焦點,做到這一點
- 13. 如何應對從另一個應用程序獲取焦點?
- 14. 如何跟蹤應用程序的z順序/焦點?
- 15. 如何避免進程從C#應用程序竊取焦點?
- 16. WaitForExit過程結束時,應用程序失去焦點
- 17. 用多個JPanel保持焦點的Java小應用程序
- 18. 當它使用sendBroadcast和ACTION_MEDIA_MOUNTED時,應用程序失去焦點
- 19. 維護用戶控件的焦點Windows應用程序
- 20. 使用標籤來改變在Android應用程序的焦點
- 21. ios:禁用應用程序焦點時的警報通知(OneSignal)
- 22. Flash應用程序接收沒有焦點的鼠標事件
- 23. 檢測應用程序是否因UILocalNotification而引起焦點
- 24. Qt應用程序,焦點和顯示/隱藏功能
- 25. 自動啓動應用程序,無焦點
- 26. Windows應用程序聚焦:爲什麼需要點擊?
- 27. C++防止Windows應用程序竊取焦點
- 28. UWP:檢測應用程序獲得/失去焦點
- 29. C#:檢測哪個應用程序有焦點
- 30. WM_SETFOCUS,獲取剛剛失去焦點的應用程序
不錯的解決方案邁克,偉大的工作。我覺得雖然ActiveWindow.Active屬性應該總是返回true,否則它不是活動窗口呢? – 2012-03-26 03:53:28