Click here to Skip to main content
16,018,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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:
C#
// 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;
    }
}
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 ?
 
Share this answer
 
Comments
MohRizwan 27-Aug-13 5:40am    
Thanks Mr.Billwoodruff for your reply .I tried your code but think its not working in my case.
I have tried it. actually my problem is that i am using two forms separately. I tried it even in menu strip tool but still the problem exists.
Any how thanks for your reply.
JSingh_Freelancer 16-Mar-16 6:11am    
Solution for this is: Go to the properties of 'notifyIcon->visible : false' at application startup

thanks
:)
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.
 
Share this answer
 
Comments
amitsalvi007 1-Jun-15 6:16am    
how to check icon already exists in system tray..?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900