托盘问题中的多个通知图标 [英] Multiple Notify icon in tray issue

查看:80
本文介绍了托盘问题中的多个通知图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

我遇到通知图标问题。

我正在使用两个单独打开的表格或我们可以说的单独表格,

我在两者中都有通知图标,但在我的代码中我只使用一种形式。

按钮点击另一个表单将打开..但是最小化我得到的很多托盘中的图标每次单击新窗口窗体外观。可能有人帮我了吗





private void btn_Minimize_Click(object sender,EventArgs e)

{

this.WindowState = FormWindowState.Minimized;

this.ShowInTaskbar = false;



notifyIcon1.BalloonTipTitle =最小化到托盘应用程序;

notifyIcon1.BalloonTipText =您已成功最小化您的表单。;



if(FormWindowState.Minimized = = this.WindowState)

{

notifyIcon1.Visible = true;

this.ShowInTaskbar = false;

//notifyIcon1.ShowBalloonTip(500);

this.Hide();

}

else if(FormWindowState.Normal == this。 WindowState)

{

//notifyIcon1.Visible = false;

this.Sho w();

}

}







i在表单_resizee事件中尝试了它,但它没有工作

Hi Friends ,
I am Having a trouble with notify icon.
I am using Two forms which is opened individually Or seperate forms we can say,
I am having notify icon in both , but in my code i am using only in one form .
on button click the other form will open..but on minimizing i am getting many icons in tray for each click on new window form appearance. could some one help me out


private void btn_Minimize_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;

notifyIcon1.BalloonTipTitle = "Minimize to Tray App";
notifyIcon1.BalloonTipText = "You have successfully minimized your form.";

if (FormWindowState.Minimized == this.WindowState)
{
notifyIcon1.Visible = true;
this.ShowInTaskbar = false;
//notifyIcon1.ShowBalloonTip(500);
this.Hide();
}
else if (FormWindowState.Normal == this.WindowState)
{
//notifyIcon1.Visible = false;
this.Show();
}
}



i tried it in form _resizee event but its not working

推荐答案

你遇到了很多人都遇到的问题(和MSDN一直有无尽的抱怨)在TaskBar的Notification区域显示同一个TaskBar Notify Icon的多个副本,当你将鼠标悬停在它们上时,有时会神秘地消失,但问题的根源通常是人们没有实现TaskBar Notification区域图标的用途。



TaskBar通知区域图标通常用于永远在线的Windows应用程序,通常不会呈现用户界面;它们通常用于触发显示最小化的窗体窗口。



我相信你知道,任务栏通知图标可以显示上下文菜单,气球工具提示等。



触发已经最小化的表单窗口的显示意味着通过将Form的'ShowInTaskBar设置为'true,并让用户单击主要。



所以,这就是Windows桌面应用程序的约定我们打算做什么,而且,现在就在桌面上,让我们违反惯例:



我发现的唯一有点可靠的技术(我没有在.NET FrameWork 4.5之外测试过)在Form最小化时呈现TaskBar Notification区域图标,然后恢复单击图标时窗体到窗口状态正常如下所示:
You are running into a problem many people have (and MSDN has had endless complaints about) with multiple copies of the same TaskBar Notify Icon showing up in the Notification area of the TaskBar, sometimes mysteriously vanishing to leave one in place as you mouse over them, but the "root" of the problem is, most often, that people don't realize what TaskBar Notification area Icons are meant to be used for.

TaskBar Notification area Icons are most often used for always-on windows applications that, in general, do not present a user-interface; they are typically not used to trigger the showing of a minimized Form Window.

As I am sure you are aware of, a TaskBar Notification Icon can present a context-menu, balloon Tooltip, etc.

Triggering the "showing" of a Form Window that has been minimized is meant to be done by having the Form's 'ShowInTaskBar set to 'true, and having the user click in the main.

So, that's what the conventions for Windows Desktop Applications intend for us to do, and, now that's on the table, let's violate the conventions:

The only somewhat reliable technique I have found (and I have not tested it outside .NET FrameWork 4.5) for presenting a TaskBar Notification area Icon when a Form is Minimized, and then restoring the Form to WindowState Normal when the Icon is clicked is done like this:
// hard-coded filepath to Icon
private const string iconFilePath = @"C:\?\?\?\SomeIcon.ico";

// click event handler for the NotifyIcon
private void notifyIcon1_Click(object sender, EventArgs e)
{
    // you could modify this to deal with the previous
    // WindowState being 'Maximized, if you took the trouble
    // to set a 'flag when transitioning from Max to Min state
    this.WindowState = FormWindowState.Normal;
}

// resize event handler for the Form
// we're going to re-load the Icon every time
// the Form is minimized
private void Form3_Resize(object sender, EventArgs e)
{
    if (WindowState == FormWindowState.Minimized)
    {
        notifyIcon1.Icon = Icon.ExtractAssociatedIcon(iconFilePath);
        notifyIcon1.Visible = true;
    }
    else
    {
        // kill the icon
        notifyIcon1.Icon = null;
    }
}

这可能是邪恶的代码,我建议你仔细考虑使用它吧。



更严重的是,如果您显示多个表单,并且总有一个主表单可见,并且您不希望辅助表单显示在TaskBar中:为什么不在菜单上显示主窗体,可以让你打开任何隐藏/最小化的辅助表格吗?

It's possible this could be "evil code," and I suggest you think carefully about using it :)

More seriously, if you are having multiple Forms displayed, and there's always one "main Form" visible, and you don't want the "secondary" Forms to show up in the TaskBar: why not have a menu on the main Form, that lets you open any hidden/minimized secondary Forms ?


我有一个条件检查是否已经存在通知图标,如果没有图标可见每个按钮单击哪里新表格已打开。
i have a put a condition to check whether there already exists a notify icon ,if not icon visible in each button click where new form is opened.


这篇关于托盘问题中的多个通知图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆