場景
WinForm 應用,使用了 DevExpress.XtraEditors.TextEdit 控件的 KeyPress 和 Leave 事件。
期望在 TextEdit 上按下回車鍵或者當 TextEdit 失去焦點時進行相關驗證並彈窗提示。
問題
彈窗顯示並關閉后,TextEdit 默認是 Focused 的狀態,如果這時想切換至其他模塊,會觸發 Leave 事件進行二次彈窗。
解決
TextEdit 沒有 LostFocus 方法。
當進行第一次彈窗時,設置其他控件獲取焦點,這樣彈窗關閉的時候 TextEdit 就不是 Focused 的狀態了。
我這里使用的是 TextEdit 所在的容器 GroupControl:GroupControlName.Focus();