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 ~