A Preliminary Study of WPF -- using the notifyicon in the winform library to implement the tray Applet

Source: Internet
Author: User

Before going to bed the night before, I came up with the idea of implementing a small software. The interface was prepared to adopt a similar intelliyicon interface similar to demon tools. When I came back from today's tour and was ready to write it, I found that the tray control was not found in the toolbar. If not, implement it by yourself. refer toCodeSample, so I wrote the next one as well as laying the groundwork for the next small software ~

The running interface is as follows:

Figure 1 Figure 2

 

There are few codes, as shown below:


Using System;
Using System. windows;
Using System. Windows. forms;
Using System. drawing;

namespace royal
{< br> Public partial class venture Ray: window
{< br> private policyicon = null ;

PublicRay ()
{
Initializecomponent ();

Initialtray ();
}

Private   Void Initialtray ()
{
// Hide main form
This . Visibility = Visibility. hidden;

// Set attributes of a tray
Yyicon =   New Yyicon ();
Notifyicon. balloontiptext =   " Invalid Ray runnning... " ;
Yyicon. Text =   " Ray " ;
Yyicon. icon =   New System. Drawing. Icon ( " Http://www.cnblogs.com/res/spring.ico " );
Policyicon. Visible =   True ;
Notifyicon. showballoontip ( 2000 );
Notifyicon. mouseclick + =   New System. Windows. Forms. mouseeventhandler (policyicon_mouseclick );

// Set Menu items
Menuitem setting1 =   New Menuitem ( " Setting1 " );
Menuitem setting2 =   New Menuitem ( " Setting2 " );
Menuitem setting =   New Menuitem ( " Setting " , New Menuitem [] {setting1, setting2 });

// help options
menuitem help = New menuitem ( " help " );

// about options
menuitem about = New menuitem ( " about " );

// exit menu item
menuitem exit = New menuitem ( " exit " );
exit. click += New eventhandler (exit_click );

//Associated tray Control
Menuitem [] Childen= NewMenuitem [] {setting, help, about, exit };
Notifyicon. contextmenu= NewContextmenu (childen );

// Triggered when the form status changes
This . Statechanged + =   New Eventhandler (explorray_statechanged );
}

///   <Summary>
/// Click
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private   Void Notifyicon_mouseclick ( Object Sender, system. Windows. Forms. mouseeventargs E)
{
// If you left-click
If (E. Button = Mousebuttons. Left)
{
If ( This . Visibility = Visibility. Visible)
{
This . Visibility = Visibility. hidden;
}
Else
{
This . Visibility = Visibility. visible;
This . Activate ();
}
}
}

///   <Summary>
/// Triggered when the form status changes
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private   Void Systray_statechanged ( Object Sender, eventargs E)
{
If ( This . Windowstate = Windowstate. Minimized)
{
This . Visibility = Visibility. hidden;
}
}

///   <Summary>
/// Exit option
///   </Summary>
///   <Param name = "sender"> </param>
///   <Param name = "E"> </param>
Private   Void Exit_click ( Object Sender, eventargs E)
{
If (System. Windows. MessageBox. Show ( " Sure to exit? " ,
" Application " ,< br> messageboxbutton. yesno,
messageboximage. Question,
messageboxresult. No) = Messageboxresult. Yes)
{
System. Windows. application. Current. Shutdown ();
}
}
}
}

 

 

Download the project source code:/files/Royal enhome/Royal en.rar. Sincerely hope to learn and exchange with you ~

 

 

 

 

 

 

 

 

 

 

 


 

 

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.