[英]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.