C# .NET - How to use timer control with notify Icon.

Asked By Sreelakshmi on 22-May-12 03:35 AM
I have developed a windows forms application with notify icon with out form.that means when I debug the application,
It shows only the notify Icon in the system tray.I used context menu strip with that notify icon.till that part its working fine...!
But now my requirement is I want use timer control with it.When the timer ticks the notify icon notify icon should get displayed in the system tray.Please help me how to do this.....! Here is the code Used to develop the notify icon and context menu strip in Program.cs file
 [STAThread]
        static void Main()
        {


            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
           //Application.Run(new Form1());
            Application.EnableVisualStyles();
            NotifyIcon notifyIconComplaint = new NotifyIcon();
            ContextMenu contextMenuComplaint = new ContextMenu();
            MenuItem menuitem1 = new MenuItem();           
            contextMenuComplaint.MenuItems.AddRange(new MenuItem[] { menuitem1 });
            menuitem1.Index = 0;
            menuitem1.Text = "View Details";
            menuitem1.Click += new EventHandler(menuitem1_Click);
            MenuItem menuItem6 = new MenuItem();
            contextMenuComplaint.MenuItems.AddRange(new MenuItem[] { menuItem6});
            menuItem6.Index = 1;
            menuItem6.Text = "-----------------------";
            MenuItem menuitem5 = new MenuItem();
            contextMenuComplaint.MenuItems.AddRange(new MenuItem[] { menuitem5 });
            menuitem5.Index = 2;
            menuitem5.Text = "Exit";
            menuitem5.Click += new EventHandler(menuitem5_Click);            
            notifyIconComplaint.Icon = new Icon(@"C:\\1.ico");
            notifyIconComplaint.Text ="Warning Message ";           
            notifyIconComplaint.ContextMenu = contextMenuComplaint;
            notifyIconComplaint.Visible = true;
            notifyIconComplaint.BalloonTipTitle = "Warning Message ";
            notifyIconComplaint.BalloonTipText = "Complaint has been raised";
            notifyIconComplaint.ShowBalloonTip(3000);
            Application.Run();
            notifyIconComplaint.Visible = false;           
          }
I need to use timer control with this code....!Please help me.
Thanks in Advance.
dipa ahuja replied to Sreelakshmi on 22-May-12 04:03 AM
1. Add NotifyIcon and ContexMenuStrip from the toolBox to the window Form
 
2. Set the following properties of the NotifyIcon from the property window:
 
3. Take a Button and write the code in its click event
private void button1_Click(object sender, EventArgs e)
{
  //display menustrip   
  notifyIcon1.ShowBalloonTip(1);
 
  //hide form   
  this.Visible = false;
}
4. Add a menu item in ContenxMenuStip : Close and add the click event of menu item this way:
 
private void CloseToolStripMenuItem_Click(object sender, EventArgs e)
{
  //hide menustrip
  notifyIcon1.Visible = false;
  
  //display form
  this.Show();
}
 
 
Somesh Yadav replied to Sreelakshmi on 22-May-12 04:20 AM
check this,
http://www.morkalork.com/mork/article/47/How_to_use_the_timer_control_in_C
http://www.mstecharticles.com/2012/01/c-implementing-systemtray-using.html
Sreelakshmi replied to dipa ahuja on 23-May-12 03:47 AM
Thanks for your reply...!My requirement: I developed a notify icon with out form.I need timer to perform some action and based on that action the message should be displayed.How to do this....!In my application timer.Elapsed( ) event is not firing.I use timer to check whether the record got inserted in database,If so displays a message with the notify icon that Record inserted. How to do this please help me...........,!
Sreelakshmi replied to Somesh Yadav on 23-May-12 03:51 AM
Thanks for ur reply...!I have r referred those sites.But those are not much useful for my requirement.Can give any idea on this....!