Winforms Devexpress PopupContainerEdit弹出窗口始终打开
我正在使用winform DevXPress库。 现在需要基于PopupContainerEdit创建一个控件,但是这个控件必须有一些行为,比如当它聚焦时,弹出窗口打开,当失去焦点时,弹出窗口关闭 这是我正在使用的代码,但是在获得焦点后弹出窗口会消失Winforms Devexpress PopupContainerEdit弹出窗口始终打开,winforms,c#-3.0,devexpress,Winforms,C# 3.0,Devexpress,我正在使用winform DevXPress库。 现在需要基于PopupContainerEdit创建一个控件,但是这个控件必须有一些行为,比如当它聚焦时,弹出窗口打开,当失去焦点时,弹出窗口关闭 这是我正在使用的代码,但是在获得焦点后弹出窗口会消失 public class HelpEdit : PopupContainerEdit { private PopupContainerControl _container; private GridControl _gridCont
public class HelpEdit : PopupContainerEdit {
private PopupContainerControl _container;
private GridControl _gridControl;
private GridView _gridView;
[DefaultValue("")]
[DXCategory("Data")]
[AttributeProvider(typeof(IListSource))]
public object Datasource {
get { return _gridControl.DataSource; }
set { _gridControl.DataSource = value; }
}
public HelpEdit() : base() {
_container = new PopupContainerControl();
this.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.Standard;
this._gridControl = new GridControl();
this._gridControl.Dock = DockStyle.Fill;
this._gridView = new GridView(_gridControl);
_container.Controls.Add(_gridControl);
_container.Size = new Size(this.Width, 250);
this.Properties.PopupControl = _container;
this.Properties.PopupControl.Size = new Size(this.Width, 250);
}
protected override void OnGotFocus(EventArgs e) {
base.OnGotFocus(e);
this.ShowPopup();
}
protected override void OnLostFocus(EventArgs e) {
base.OnLostFocus(e);
this.ClosePopup();
}
}
弹出窗口消失,因为一旦弹出容器控件(
\u container
)获得焦点,它就会被代码关闭。您不应该在OnLostFocus()覆盖中关闭弹出窗口,因为PopupContainerEdit
的base.OnLostFocus
方法已包含用于关闭弹出窗口的正确代码。或使用以下代码有条件地关闭弹出窗口:
protected override void OnLostFocus(EventArgs e) {
if(IsPopupOpen && !EditorContainsFocus)
ClosePopup(PopupCloseMode.Immediate);
base.OnLostFocus(e);
}