最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
用托盘控制windows服务的c#实现
时间:2022-07-02 11:06:37 编辑:袖梨 来源:一聚教程网
孟子e章给出的vb代码,现在从这个代码翻译成c#,给习惯c#的人参考
需要注意的是图片一定需要是ico格式,否则可能会导致托盘的不显示
using System;
namespace UBISerialsController
{
///
/// Class1 的摘要说明。
///
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: 在此处添加构造函数逻辑
//
}
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("停止",new EventHandler(StopService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("暂停",new EventHandler(PauseService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("继续",new EventHandler(ContiuneService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("开始",new EventHandler(StartService)));
cm.MenuItems.Add("-");
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("关于",new EventHandler(About)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("退出",new EventHandler(Exit)));
ni.ContextMenu=cm;
需要注意的是图片一定需要是ico格式,否则可能会导致托盘的不显示
using System;
namespace UBISerialsController
{
///
/// Class1 的摘要说明。
///
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: 在此处添加构造函数逻辑
//
}
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("停止",new EventHandler(StopService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("暂停",new EventHandler(PauseService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("继续",new EventHandler(ContiuneService)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("开始",new EventHandler(StartService)));
cm.MenuItems.Add("-");
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("关于",new EventHandler(About)));
cm.MenuItems.Add(new System.Windows.Forms.MenuItem("退出",new EventHandler(Exit)));
ni.ContextMenu=cm;
相关文章
- 无主之地4支线电击疗法怎么做 支线电击疗法图文攻略 09-16
- 超级机器人大战Y隐藏机体怎么解锁 莱汀强化与后援获取攻略 09-16
- 无主之地4支线任务苏威杯怎么做 支线任务苏威杯图文攻略 09-16
- 原神挪德卡莱武器图纸怎么拿 挪德卡莱武器图纸获取方法 09-16
- 魔兽世界泰达希尔夜刃捕食者在哪抓-泰达希尔夜刃捕食者位置解析 09-16
- 超级机器人大战Y怎么自定义BGM 背景音乐替换教程 09-16