I am having issues testing which icon my notifyIcon is using.
I have a notifyicon instantiated for my program. When the program runs I assign an icon to it in my code.
public Form1()
{
InitializeComponent();
notifyIcon1.Icon = Properties.Resources.LogoIcon;
}
I have 2 buttons, one which starts my timer, and 1 which stops my timer. The timer event is suppose to check which icon is currently being used and switch it to the other option, but it doesn’t work using my test.
Timer miniClock = new Timer();
private void btnStartTimer_Click(object sender, EventArgs e)
{
miniClock.Interval = 1000;
miniClock.Tick += new EventHandler(MiniClockEventProcessor);
miniClock.Start();
}
private void MiniClockEventProcessor(Object myObject, EventArgs myEventArgs)
{
if (notifyIcon1.Icon == Properties.Resources.AlertIcon)
{
notifyIcon1.Icon = Properties.Resources.LogoIcon;
}
else
notifyIcon1.Icon = Properties.Resources.AlertIcon;
}
private void btnStopTimer_Click(object sender, EventArgs e)
{
miniClock.Stop();
btnTest.Enabled = true;
}
The frustrating part is when I start the timer, it will change the icon, but my test fails and it will only switch the icon in the else statement because there’s no criteria to it except that it fails the if statement? How can I test which icon is currently being used, and then switch the icon to it’s counterpart on the timer event call?
I think it’s easier to relay on some
statethen toIconitself.I imagine that yo setup
AlertIconorLogonIcon, based on some event, or on some changed state notification. It’s better to have somewhere the simpleboolstatevariable that indicates what happens.For example , to explain what am I talking about, is a pseudocode :
On recived alert the property
IsAlertState = true.Something like this.