window| Control Mencius E Chapter of the VB code, now from this code translated into C #, to the people accustomed to C # Reference
It is important to note that the image must be in the ICO format, otherwise it may cause the tray to not display
Using System;
Namespace Ubiserialscontroller
{
<summary>
Summary description of the CLASS1.
</summary>
public class Class1
{
Static System.ServiceProcess.ServiceController SC;
Static System.Windows.Forms.NotifyIcon ni;
static System.Windows.Forms.ContextMenu cm;
Static System.Timers.Timer Timer;
Public Class1 ()
{
//
TODO: Add constructor logic here
//
}
static void Main ()
{
Try
{
Sc=new System.ServiceProcess.ServiceController ("ubiserials");
Ni=new System.Windows.Forms.NotifyIcon ();
Ni. Visible=false;
Cm=new System.Windows.Forms.ContextMenu ();
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("Stop", New EventHandler (StopService));
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("Pause", new EventHandler (Pauseservice));
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("Continue", New EventHandler (Contiuneservice));
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("Start", New EventHandler (StartService));
Cm. Menuitems.add ("-");
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("about", new EventHandler (about));
Cm. Menuitems.add (New System.Windows.Forms.MenuItem ("Exit", new EventHandler (exit));
Ni. CONTEXTMENU=CM;
Ni. Visible=true;
Setuptimer ();
System.Windows.Forms.Application.Run ();
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show (ex. Message.tostring ());
}
}
private static void Getservicestate ()
{
Sc. Refresh ();
Switch (SC. Status)
{
Case System.ServiceProcess.ServiceControllerStatus.Stopped:
{
Ni. Icon=new System.Drawing.Icon ("Stopped.ico");
Cm. Menuitems[0]. Enabled=false;
Cm. MENUITEMS[1]. Enabled=false;
Cm. MENUITEMS[2]. Enabled=false;
Cm. MENUITEMS[3]. Enabled=true;
Break
}
Case System.ServiceProcess.ServiceControllerStatus.Running:
{
Ni. Icon=new System.Drawing.Icon ("Started.ico");
Cm. Menuitems[0]. Enabled=true;
Cm. MENUITEMS[1]. Enabled=true;
Cm. MENUITEMS[2]. Enabled=false;
Cm. MENUITEMS[3]. Enabled=false;
Break
}
Case System.ServiceProcess.ServiceControllerStatus.Paused:
{
Ni. Icon=new System.Drawing.Icon ("Paused.ico");
Cm. Menuitems[0]. Enabled=false;
Cm. MENUITEMS[1]. Enabled=false;
Cm. MENUITEMS[2]. Enabled=true;
Cm. MENUITEMS[3]. Enabled=false;
Break
}
Default
{
Ni. Icon=new System.Drawing.Icon ("Paused.ico");
Break
}
}
}
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.