Problem with controls in MDI form

五迷三道 提交于 2019-12-11 05:48:01

问题


I have placed a button on MDI form , now when I open a child form , the button remains on top and distracts the child form , is there a way to solve it? I have done following to send the button back when any child is activated.But I am wondering to call button1.BringToFront();

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

I tried following but it doesnt work.

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

I think its a lasting bug of .net , there are many posts trying to solve it , using dock with a panel etc , but docking just for a button makes the application work space less.


回答1:


I found the answer to my question ! here is how I implemented it , the post here was what I was missing.

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


来源:https://stackoverflow.com/questions/3698445/problem-with-controls-in-mdi-form

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!