1

I'm writing an application that shows notifications trough baloontips over notifyicon. There are two kinds of notifications I want to display - normal baloontip and clickable baloontip. I want clickable baloontips to open some url in web browser. The problem is that events stacks over baloontip. I'm not sure if this explanation says anything, so here's an example:

code:

NotifyIcon ni = new NotifyIcon();

void showClickableNotification(string title, string content, string url)
{
ni.BaloonTipClicked += new EventHandler((sender, e) => ni_BalloonTipClicked(sender, e, url));
ni.ShowBaloonTip(1, title, content, ToolTipIcon.Info);
}

void ni_BalooTipClicked(object sender, EventArgs e, string url)
{
Process.Start(url);
}

every use of showClickableNotification will assign one more url to BallonTipClicked event

I want to clear event after notification will hide, to prevent opening multiple tabs unassociated with current notification.

Also, when normal notification is shown after a clickable one it's click opens all the stacked urls as well.

I tried to assign an empty function for ni.BaloonTipClicked += emptyFunction this, but += operator just adds another event to the pool instead of overwriting it. -= does not work since I'm adding new event every time. I guess I could do some global variable that holds current url and avoid assigning new everytime (-= would work then), but it looks like cheap workaround. Is there any (correct?) way to do it?

wjtk4444
  • 47
  • 5
  • 2
    Because you are using a lambda expression for the event, you need to store the lambda somewhere first, and then unsubscribe it later. See http://stackoverflow.com/questions/1362204/how-to-remove-a-lambda-event-handler – Ron Beyer Sep 29 '15 at 13:45
  • I tried but can't understand what you want? Can you provide more details? Code? An example perhaps? – raidensan Sep 29 '15 at 13:45
  • Sorry for a bit late response, but it took me a while to test how it works (during program run, not just synthetic baloontip calls). And it works pretty well. Ballontip is always shown for minimal amount of time, but at least clicks are now handled properly. Thanks, @RonBeyer – wjtk4444 Oct 08 '15 at 12:53

0 Answers0