WPF Notification bar icons and right-click menus

Source: Internet
Author: User
Tags visibility

WPF does not have its own notification bar icon component, and you need to refer to the Windows Class Library with the following specific code:

        Public MainWindow () {InitializeComponent ();
            icon ();
        WSL = windowstate.minimized;
            #region notification bar WindowState WSL;
        
            System.Windows.Forms.NotifyIcon NotifyIcon = null;
                private void icon () {This.notifyicon = new System.Windows.Forms.NotifyIcon (); This.notifyIcon.BalloonTipText = "ECMS service is running ..."; Sets the text to display when the program starts This.notifyIcon.Text = "ECMS service";//when minimized to the tray, the text displayed when the mouse clicks This.notifyIcon.Icon

                = new System.Drawing.Icon ("./logo_48x48.ico");//program icon this.notifyIcon.Visible = true;
                Right-click Menu--Opens menu item System.Windows.Forms.MenuItem open = new System.Windows.Forms.MenuItem ("open"); Open.
                Click + + new EventHandler (ShowWindow);
                Right-click Menu--Exit menu item System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem ("Exit"); Exit.
                Click + + new EventHandler (CloseWindow);
                Associated pallet control system.windows.forms.menuitem[] childen = new system.windows.forms.menuitem[] {open, exit};

                Notifyicon.contextmenu = new System.Windows.Forms.ContextMenu (childen);
                Notifyicon.mousedoubleclick + = Onnotifyicondoubleclick;
            THIS.NOTIFYICON.SHOWBALLOONTIP (1000);
                 } private void Onnotifyicondoubleclick (object sender, EventArgs e) {/* * This section of code needs to explain: * When the window is normal double-click the icon to execute the code is such a process: * this. Show ()-->windowstate changed from Normail to minimized-->window_statechanged event execution (this. Hide ())-->windowstate from minimized to normal--> window Hide * Double-click the icon to execute this code is a process: * this.
                Show ()-->windowstate changed from Normail to Minimized-->windowstate from minimized to normal--> window display * * This.
                Show (); This. WindowState = Windowstate.minimized; This.
            WindowState = Windowstate.normal;
                 Hidden taskbar icon when private void Window_statechanged (object sender, EventArgs e) {//Window minimized if (WindowState = = windowstate.minimized) {this.
                Hide (); } private void ShowWindow (object sender, EventArgs e) {this.
                Visibility = System.Windows.Visibility.Visible; This.
                ShowInTaskbar = true; This.
            Activate (); } private void Hidewindow (object sender, EventArgs e) {this.
                ShowInTaskbar = false; This.
            Visibility = System.Windows.Visibility.Hidden; } private void CloseWindow (object sender, EventArgs e) {System.Windows.Applicati On.
            Current.shutdown (); } #endregion


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.