我该如何指定MessageBox
在任务栏中使用哪个图标?没有MessageBox.Show
的重载可以让我选择任务栏图标,只能选择在实际窗体中使用的图标。
我该如何指定MessageBox
在任务栏中使用哪个图标?没有MessageBox.Show
的重载可以让我选择任务栏图标,只能选择在实际窗体中使用的图标。
我认为无法更改任务栏图标;您唯一的选择是制作自己的MessageBox。
简短回答:你不能这样做。
简短回答#2:你需要自己创建一个表单,并手动显示它。
MessageBox
的图标,我发现一种方法可以避免创建自定义表单,但是我们需要创建一个虚拟表单(或者您可以将其更改为匿名表单): using (Form dummy = new Form() {
Icon = Properties.Resources.ico_Main_Logo
, TopMost = true
, FormBorderStyle = System.Windows.Forms.FormBorderStyle.None
, Size = new System.Drawing.Size(0,0)
, BackColor = Color.White
, TransparencyKey = Color.White
})
{
dummy.Show();
MessageBox.Show(dummy, "This is a MessageBox with Icon at Taskbar and on top of all windows", "Title Text", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
MessageBox
的图标。(我使用应用程序设置加载图标,您也可以从磁盘等其他方式加载。)
- 将 MessageBox
窗口显示在其他窗口的顶部。(如果不想要这个效果,请设置 TopMost = false
。)
- 不要在任务栏上显示 MessageBox
的图标。(只需在使用时初始化一个简单的表单并删除 dummy.Show();
行。)MessageBox
图标:MessageBox.Show(new Form(), "This is a MessageBox Hide it from Taskbar", "Title Text", MessageBoxButtons.OK, MessageBoxIcon.Information);
无论如何,我只想分享我的新发现,希望能对他人有所帮助。谢谢。
这个方法很好用,但是我不知道为什么,即使我将表单的Size
设置为(0, 0)
,它的大小仍然为131x37!!!但是因为该表单设置为透明,所以它不可见,鼠标指针会穿过它。