代码之家  ›  专栏  ›  技术社区  ›  Thunder

MDI窗体中的控件有问题

  •  1
  • Thunder  · 技术社区  · 15 年前

    我已经在MDI窗体上放置了一个按钮,现在当我打开一个子窗体时,该按钮保持在顶部并且分散了子窗体的注意力,有什么方法可以解决它吗? 我已经做了如下发送按钮回来时,任何孩子是激活了。但是我想叫按钮1.BringToFront();

    private void MDIParent1_MdiChildActivate(object sender, EventArgs e)
    {
        button1.SendToBack();
    }
    

    我试过跟踪,但没用。

    private void MDIParent1_Enter(object sender, EventArgs e)
    {
        button1.BringToFront();
    }
    

    我认为这是一个持久的错误.net,有很多帖子试图解决它,使用一个面板等对接,但对接只是一个按钮,使应用程序的工作空间更少。

    1 回复  |  直到 15 年前
        1
  •  0
  •   Community Mohan Dere    8 年前

    我找到了问题的答案!下面是我如何实现它的帖子 here

    public MDIParent1()
            {
                InitializeComponent();
                foreach (var ctl in this.Controls)
                {
                    if (ctl is MdiClient)
                    {
                        (ctl as MdiClient).GotFocus  += Client_gotfocus;
                        (ctl as MdiClient).LostFocus  += Client_lostfocus;
                        break;
                    }
                }
    
            }
            private void Client_gotfocus(object sender, EventArgs e)
            {
                button1.BringToFront();
            }
            private void Client_lostfocus(object sender, EventArgs e)
            {
                button1.SendToBack ();
            }
    
    推荐文章