ToolStripDropDown丢失鼠标自动关闭



不知道如何解释,但:

  • 存在由ToolStripDropDown构成的控制MyPopup
  • 有许多基于CCD_ 3的控件(称之为弹出窗口(
  • Form打开弹出窗口没有问题
  • 但是从弹出窗口打开弹出窗口的问题

问题是,在子弹出窗口关闭后,即使其父Form获得焦点,父弹出窗口也会留在屏幕上。关闭卡住的父弹出窗口的唯一方法是(用鼠标(将焦点对准它,然后点击Esc

为了让弹出窗口能够显示另一个弹出窗口,我必须欺骗Closing事件:

    void Popup_Closing(object sender, ToolStripDropDownClosingEventArgs e)
    {
        // prevent from closing when stay
        if (_stay && e.CloseReason != ToolStripDropDownCloseReason.CloseCalled )
        {
            e.Cancel = true;
            return;
        }
    }

在关闭子弹出窗口之前或之后,父弹出窗口具有:

  • CCD_ 7的值为CCD_
  • 则CCD_ 9的值为CCD_

我试图用以下内容将鼠标焦点"带回"父弹出窗口:

  • TopLevel=true运气不佳
  • Focus();运气不佳
  • Focused=true;运气不佳
  • AutoClose=true;运气不佳
  • Captured=true;运气不佳

还试着将上述值设置为False,然后设置为True,但仍然没有成功。

这里还有一些有用或不有用的代码:

public class MyPopup : UserControl
{
    protected bool _stay = false;
    private ToolStripDropDown _popup;
    private ToolStripControlHost _host;
    public MyPopup()
    {
        // create popup
        _popup = new ToolStripDropDown();
        _popup.Margin = _popup.Padding = Padding.Empty;
        _popup.AutoSize = false;
        _popup.Closing += Popup_Closing;
        // add host
        _host = new ToolStripControlHost(this);
        _host.Margin = _host.Padding = Padding.Empty;
        _host.AutoSize = false;
        _popup.Items.Add(_host);
    }
    public void Show(Control parent, int x, int y)
    {
        _popup.Show(parent, x, y);
    }
    public new void Hide()
    {
        _popup.Close();
    }
    private void Popup_Closing(object sender, ToolStripDropDownClosingEventArgs e)
    {
        // prevent from closing when stay
        if (_stay && e.CloseReason != ToolStripDropDownCloseReason.CloseCalled )
        {
            e.Cancel = true;
            return;
        }
    }
    protected void PopupChildClosedDefaultEvent(object sender, EventArgs e)
    {
        // hide popup if mouse is outside of client region when closing child popup
        if (!ClientRectangle.Contains(PointToClient(MousePosition)))
            Hide();
        else
        {
            // >> here I am trying different things <<
            _popup.AutoClose = false;
            _popup.AutoClose = true;
        }
    }
}
public class PopupParent: MyPopup
{
    private void TestChildren()
    {
        _stay = true;
        PopupChild popup = new PopupChild();
        popup.Show(button1, 0, 0);
        popup.Closed += PopupChildClosedDefaultEvent;
        _stay = false;
    }
}
public class PopupChild: MyPopup
{
}

问题:在"损坏"的弹出窗口失去自动关闭鼠标事件的能力(点击客户端区域以外的某个地方(后,有什么方法可以修复它吗

好吧,早上给大脑带来了一些新鲜感,我用以下方法解决了这个问题:

            _popup.Close();
            _popup.Show(_parent, _x, _y);

所以我必须重新显示弹出窗口,让它像以前一样工作。它闪烁,但有效。

相关内容

  • 没有找到相关文章

最新更新