gpt4 book ai didi

c# - 隐藏 .NET MessageBox 的任务栏图标

转载 作者:行者123 更新时间:2023-11-30 13:31:37 24 4
gpt4 key购买 nike

是否可以调用静态 MessageBoxShow() 方法,使其没有任务栏图标或具有自定义图像?我正在尝试寻找构建自定义 MessageBox 类的替代方法。

谢谢。

我尝试通过以下方式使用 DefaultDesktopOnly 选项:

if (MessageBox.Show("Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}

但是任务栏中仍然有一个图标,主窗体也开始崩溃。如果重要的话,我在Win7中。 DefaultDesktopOnly 是否存在稳定性问题?

最佳答案

您需要为 MessageBox 提供一个所有者窗口,该窗口具有(或不具有)自身的图标,以使对话框不单独显示。如果您从打开的表单中调用 MessageBox,您可以将表单作为第一个参数传递,使其成为所有者:

// Assume "this" is a form, not valid from any other class
if (MessageBox.Show(this, "Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}

但是如果你的程序此时没有其他可见的 GUI,你可以简单地创建一个虚拟表单来为它提供一个所有者,就像这样:

// A new, invisible form is created as the MessageBox owner, this prevents it from appearing in the taskbar
if (MessageBox.Show(new Form(), "Are you sure you would like to do something?", "Title", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//Do stuff
}

关于c# - 隐藏 .NET MessageBox 的任务栏图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20196410/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com