h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

AppNotifyIcon

InitializeComponent
namespace TestEasyCon
{
    partial class AppNotifyIcon
    {
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AppNotifyIcon));
            this.nfyIcon = new System.Windows.Forms.NotifyIcon(this.components);
            this.contextMenuStrip = new System.Windows.Forms.ContextMenuStrip(this.components);
            this.tsmRestore = new System.Windows.Forms.ToolStripMenuItem();
            this.tsmExit = new System.Windows.Forms.ToolStripMenuItem();
            this.tmrForNfy = new System.Windows.Forms.Timer(this.components);
            this.contextMenuStrip.SuspendLayout();
            this.SuspendLayout();
            //
            // nfyIcon
            //
            this.nfyIcon.ContextMenuStrip = this.contextMenuStrip;
            this.nfyIcon.Icon = ((System.Drawing.Icon)(resources.GetObject("nfyIcon.Icon")));
            this.nfyIcon.Text = "EasyCon";
            this.nfyIcon.Visible = true;
            this.nfyIcon.BalloonTipShown += new System.EventHandler(this.notifyIcon1_BalloonTipShown);
            //
            // contextMenuStrip
            //
            this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.tsmRestore,
            this.tsmExit});
            this.contextMenuStrip.Name = "contextMenuStrip1";
            this.contextMenuStrip.Size = new System.Drawing.Size(124, 48);
            //
            // tsmRestore
            //
            this.tsmRestore.Name = "tsmRestore";
            this.tsmRestore.Size = new System.Drawing.Size(123, 22);
            this.tsmRestore.Text = "Restore";
            //
            // tsmExit
            //
            this.tsmExit.Name = "tsmExit";
            this.tsmExit.Size = new System.Drawing.Size(123, 22);
            this.tsmExit.Text = "Exit";
            //
            // tmrForNfy
            //
            this.tmrForNfy.Tick += new System.EventHandler(this.tmrForNfy_Tick);
            //
            // AppNotifyIcon
            //
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Name = "AppNotifyIcon";
            this.Size = new System.Drawing.Size(10, 10);
            this.contextMenuStrip.ResumeLayout(false);
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.NotifyIcon nfyIcon;
        private System.Windows.Forms.ContextMenuStrip contextMenuStrip;
        private System.Windows.Forms.ToolStripMenuItem tsmRestore;
        private System.Windows.Forms.ToolStripMenuItem tsmExit;
        private System.Windows.Forms.Timer tmrForNfy;
    }
}

Code Behind

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TestEasyCon
{
    public partial class AppNotifyIcon : UserControl
    {
        public AppNotifyIcon()
        {
            InitializeComponent();
            nfyIcon.DoubleClick += new EventHandler(OpenApp);
            tsmRestore.Click += new EventHandler(OpenApp);
        }


        #region Declaration
        bool FromTrayIconDoubleClick = false;
        public delegate void RestoreClickedEventHandler(object sender, EventArgs e);
        public event RestoreClickedEventHandler RestoreClicked;
        #endregion


        #region Functions
        private void OpenApp(object sender, EventArgs e)
        {
            if (RestoreClicked != null)
                RestoreClicked(this, e);
        }
        /// <summary>
        ///  To Restore Application
        /// </summary>
        /// <param name="frm">Pass Form Name</param>
        public  void RestoreApplicaiton(Form frm)
        {
            FromTrayIconDoubleClick = true;
            frm.Show();
            frm.WindowState = FormWindowState.Normal;
            frm.Focus();
        }

        #endregion

        private void notifyIcon1_BalloonTipShown(object sender, EventArgs e)
        {
            tmrForNfy.Enabled = true;
        }

        private void tmrForNfy_Tick(object sender, EventArgs e)
        {
            nfyIcon.Visible = false;
            nfyIcon.Visible = true;
            tmrForNfy.Enabled = false;
        }    
    }
}

No comments:

Post a Comment