【问题标题】:Devexpress PopupContainerEdit popup always openDevexpress PopupContainerEdit 弹出窗口始终打开
【发布时间】:2012-12-19 20:39:50
【问题描述】:

我正在使用 winform DevExpress 库。 现在需要基于 PopupContainerEdit 创建一个控件,但是该控件必须具有一些行为,例如当它获得焦点时,弹出窗口打开,当失去焦点时弹出窗口关闭。

这是我正在使用的代码,但在获得焦点后弹出窗口消失了。

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();
    }
}

【问题讨论】:

    标签: winforms c#-3.0 devexpress


    【解决方案1】:

    您的弹出窗口消失了,因为一旦弹出容器控件 (_container) 获得焦点,它就会被您的代码关闭。您不应该在 OnLostFocus() 覆盖中关闭弹出窗口,因为 PopupContainerEdit 的 base.OnLostFocus 方法已经包含用于关闭弹出窗口的正确代码。或者使用以下代码有条件地关闭弹出窗口:

    protected override void OnLostFocus(EventArgs e) {
        if(IsPopupOpen && !EditorContainsFocus) 
            ClosePopup(PopupCloseMode.Immediate);
        base.OnLostFocus(e);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-08
      • 2016-05-11
      • 2013-06-09
      • 2011-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多