溅屏顶部的消息框

本文关键字:消息 顶部 | 更新日期: 2023-09-27 18:06:15

我有一个消息框,当用户无法加载时弹出(在这种情况下,因为他没有仓库),同时加载有一个闪屏显示数据正在加载。我尝试将TopMost设置为true,但是,是的,闪屏不是父级,所以它不起作用,所以我尝试将topplevel设置为true,但它没有做到这一点。

所以我试了:

MessageBox.Show(Splashscreen.LoadingScreen.ActiveForm, e.Message, "No warehouses", MessageBoxButtons.OK, MessageBoxIcon.Error);

但是这是交叉线程所以我得到一个:InvalidOperationException那么有没有别的方法可以把消息框设置在顶部呢?

溅屏顶部的消息框

试试这个,它会在当前打开的每个窗口的顶部显示您的消息框。

MessageBox.Show(this,
        "Your text",
        "Settings Needed",
        MessageBoxButtons.YesNo,
        MessageBoxIcon.Question,
        MessageBoxDefaultButton.Button1,
        (MessageBoxOptions)0x40000); // this is MB_TOPMOST flag

这将保持消息框在每个窗口的顶部,因为我们将MB_TOPMOST值传递给MessageBoxOptions参数。你可以访问这个网站了解更多信息。

我面临着类似的问题-我的消息框得到隐藏在SplashScreen后面。此处既不建议使用"this",也不建议使用"new Form",适用于我的WPF应用程序。然而,结构

MessageBox.Show(msg, errType, MessageBoxButton.OK, 
    MessageBoxImage.Asterisk, reply, MessageBoxOptions.ServiceNotification);
与<<p> strong> MessageBoxOptions。ServiceNotification有帮助,将MessageBox放在SplashScreen的顶部。