簡體   English   中英

在 Winform 中帶到前台事件

[英]Bring to Front event in Winform

我有一個附有 3 個表格的應用程序。 我把它都設置為 Top Most,所以每個表單看起來都像父表單的擴展。 現在用戶不希望它位於頂部。 當我將 TopMost 設置為 false 時,表單似乎是分開的。 如果這些表單中的任何一個位於頂部(通過單擊、單擊任務欄圖標,甚至使用 ALT TAB),我想將所有表單放在最前面。 我認為,如果有一個前置事件,那將解決我的問題。

對於那些需要快速准確響應的人,請嘗試我得到答案的鏈接:

BringToFront() 方法會觸發哪些事件?

當窗體被帶到 GUI 的最頂部時,會觸發 Winform "Activated" 事件。

嘗試在每個子窗體的 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM