2015-09-14 143 views
0

我有一個Windows應用程序加載了幾個組件,包括一個PropertyGrid。PropertyGrid部隊失去焦點

如果我在PropertyGrid中進行任何編輯並在PropertyGrid中的其他位置單擊,焦點將丟失並且屬性被更新。

但是,當我在PropertyGrid中進行編輯並單擊PropertyGrid以外的某個位置時,編輯光標顯示在PropertyGrid的TextBox中,並且焦點不會丟失。在其他地方點擊時是否有可能強制失去焦點?

+0

你應該提出你做了什麼努力,否則它只是要求代碼。 – MahanGM

回答

0

您可以將窗體的活動控件設置爲null。

private void propertyGrid1_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) 
{ 
    if (!this.propertyGrid1.RectangleToScreen(this.DisplayRectangle).Contains(Control.MousePosition)) 
    { 
     if (this.ActiveControl == this.propertyGrid1) { this.ActiveControl = null; } 
    } 
}