How do I prevent a popup form from taking focus from the parent

╄→尐↘猪︶ㄣ 提交于 2020-01-24 13:11:42

问题


I have a small windows.form that I use to present information when the mouse is over a regions on a windows.Form, however it takes the focus from the parent window when it is set to visible. Is there w way of preventing this - it causes the main form to flicker as it toggles between in focus and out.

c#, .net 2.0, system.windows.forms


回答1:


Paste this into your popup form class, it prevents it from being activated when shown:

    protected override bool ShowWithoutActivation {
        get { return true; }
    }



回答2:


[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

ShowWindow(popupForm.Handle, 8);

See ShowWindow Function for additional commands.



来源:https://stackoverflow.com/questions/3175567/how-do-i-prevent-a-popup-form-from-taking-focus-from-the-parent

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