繁体   English   中英

Windows窗体始终位于顶部,无法正常工作C#

[英]Windows form always on top not working c#

我搜索了该论坛,但似乎没有答案是正确的答案。

用户在浏览器中操作时,我需要显示来自systray应用程序的消息通知。

我希望此通知显示在所有内容的顶部,但是即使将其设置为TopMost或TopLevel或BringToFront或Focus,也无法实现我想要的结果。

我使用的是简单的Windows窗体,并使用systray应用程序中的ShowDialog进行显示。

请帮我 :)

PS:如果我从systray应用程序启动通知表单而未打开其他应用程序或未将其聚焦,则它运行正常,只是无法在活动的浏览器窗口前显示它

NameOfYourWindow myTopForm = new NameOfYourWindow();

myTopForm.Owner = App.Current.MainWindow;
myTopForm.ShowInTaskbar = false;
myTopForm.TopMost = true;
myTopForm.ShowDialog();
#region SetForegroundWindow
    [DllImport("kernel32.dll", ExactSpelling = true)]
    public static extern IntPtr GetConsoleWindow();
    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    public static extern bool SetForegroundWindow(IntPtr hWnd);
    #endregion
     static void Main(string[] args)
    {
        while (true)
        {

            SetForegroundWindow(GetConsoleWindow());
        }
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM