WPF control-policyicon

Source: Internet
Author: User

1. Where can I find yyicon?

Common WPF controls are basically in this namespace: system. windows. controls. The namespace is in c: \ Program Files \ reference assemblies \ Microsoft \ framework \ V3.0 \ presentationframework. DLL. That is, it is supported only after. Net framework3.0.

Isn't policyicon available in WPF?

On msdn, there is an example of the notification icon: http://msdn.microsoft.com/zh-cn/library/aa972170 (vs.90). aspx

 Using System; Using System. windows; Using System. Windows. forms; // Policyicon Control  Using System. drawing; // Icon  Public partial class  Mainwindow :Window { Yyicon Yyicon; Public Mainwindow () {initializecomponent ();} Void Click ( Object Sender, Routedeventargs E ){ // Configure and show a notification icon in the system tray  This . Policyicon = New  Yyicon (); This . Policyicon. balloontiptext ="Hello, policyicon! " ; This . Policyicon. Text = "Hello, policyicon! " ; This . Policyicon. Icon = New System. Drawing. Icon ( "Policyicon. ICO" ); This . Policyicon. Visible = True ; This . Policyicon. showballoontip (1000 );}}

It contains the policyicon control. note its namespace: system. windows. forms;, the namespace is in c: \ windows \ Microsoft. net \ framework \ v2.0.50727 \ system. windows. forms. DLL. Therefore, the policyicon control used here is actually a control provided by. NET Framework 2.0 under winform.

2. How to Use policyicon


 <  Application  X  :  Class  = "Policyiconstd. app"  Xmlns  = "Http://schemas.microsoft.com/winfx/2006/xaml/presentation"  Xmlns  :  X = "Http://schemas.microsoft.com/winfx/2006/xaml"  Shutdownmode  = "Onexplicitshutdown"  Startup  = "Applicationstartup"  Exit  = "Applicationexit"> <  Application. Resources  > </  Application. Resources  > </  Application  > 


 Using System;Using System. Collections. Generic; Using System. configuration; Using System. Data; Using System. LINQ; Using System. windows; Using System. Windows. forms; Using  Application = System. Windows. Application ; Namespace Policyiconstd { Public partial class  App :Application { Private Static  Yyicon Trayicon; Private void Applicationstartup ( Object Sender, Startupeventargs E) {removetrayicon (); addtrayicon ();} Private void Addtrayicon (){ If (Trayicon! = Null ){ Return ;} Trayicon =New  Yyicon {Icon = New System. Drawing. Icon ( "Policyicon. ICO" ), Text = "Policyiconstd" }; Trayicon. Visible = True ; Contextmenu Menu = New  Contextmenu (); Menuitem Closeitem = New Menuitem (); Closeitem. Text = "Close" ; Closeitem. Click + = New  Eventhandler ( Delegate { This . Shutdown ();}); Menuitem Additem = New  Menuitem (); Additem. Text = "Menu" ; Menu. menuitems. Add (additem); menu. menuitems. Add (closeitem); trayicon. contextmenu = menu;// Set the shortcut menu of policyicon } Private void Removetrayicon (){ If (Trayicon! = Null ) {Trayicon. Visible = False ; Trayicon. Dispose (); trayicon = Null ;}} Private void Applicationexit ( Object Sender, Exiteventargs E) {removetrayicon ();}}}

This exampleProgramThe program only starts a policyicon at the same time when the program starts. There is no other main program interface, you can add processing for other windows in the menuitem event.

Celery label: WPF

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.