[英]Bring to Front event in Winform
我有一个附有 3 个表格的应用程序。 我把它都设置为 Top Most,所以每个表单看起来都像父表单的扩展。 现在用户不希望它位于顶部。 当我将 TopMost 设置为 false 时,表单似乎是分开的。 如果这些表单中的任何一个位于顶部(通过单击、单击任务栏图标,甚至使用 ALT TAB),我想将所有表单放在最前面。 我认为,如果有一个前置事件,那将解决我的问题。
尝试在每个子窗体的 ctor 中设置父级:
ChildForm frm = new ChildForm(parentForm);
尝试使用 Win32 函数来破解前台行为:
public static class User32
{
public const int SW_HIDE = 0;
public const int SW_SHOW = 5;
public const int SW_SHOWNORMAL = 1;
public const int SW_SHOWMAXIMIZED = 3;
public const int SW_RESTORE = 9;
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool AllowSetForegroundWindow(uint dwProcessId);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
}
User32.AllowSetForegroundWindow((uint)Process.GetCurrentProcess().Id);
User32.SetForegroundWindow(Handle);
User32.ShowWindow(Handle, User32.SW_SHOWNORMAL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.