我正在使用winform DevExpress库。 现在需要创建一个基于PopupContainerEdit的控件,但是这个控件必须有一些行为,比如当它聚焦时,弹出窗口打开,当弹出窗口关闭时失去焦点。
这是我正在使用的代码,但在获得焦点后弹出dessapears。
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();
}
}
答案 0 :(得分:3)
弹出容器控件(_container
)获得焦点时,弹出窗口会因代码关闭而弹出窗口消失。您不应该在OnLostFocus()覆盖中关闭弹出窗口,因为base.OnLostFocus
的{{1}}方法已包含用于关闭弹出窗口的正确代码。或者使用以下代码有条件地关闭弹出窗口:
PopupContainerEdit