1,978
社区成员
发帖
与我相关
我的任务
分享
private void InitializeComponent_tray()
{
this.SuspendLayout();
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(320, 56);
this.ControlBox = false;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;
this.Name = "tray";
this.ShowInTaskbar = false;
this.Text = "用Visual C#做托盘程序!";
this.ResumeLayout(false);
}
private Icon printIcon ;//打印图标
private NotifyIcon TrayIcon;
private ContextMenu notifyiconMnu;
private MenuItem[] mnuItms;
/// <summary>
/// 设置证书制作和打印为托盘程序
/// </summary>
private void Initializenotifyicon()
{
CurrentMethod method = new CurrentMethod();
string first = method.ConfigGetValue("StartOrEnd");
//设定托盘程序的各个属性
TrayIcon = new NotifyIcon();
string str_path = string.Empty;
str_path = System.Windows.Forms.Application.StartupPath + "\\" + "edit.ico";
printIcon = new Icon(str_path);//打印图标
TrayIcon.Icon = printIcon;
TrayIcon.Text = "质检报告制作打印服务";
//定义一个MenuItem数组,并把此数组同时赋值给ContextMenu对象
mnuItms = new MenuItem[5];
if (first == "0")//开机自启动
{
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "开机不启动";
mnuItms[0].Click += new System.EventHandler(this.NoOpenStart);
}
else
{
mnuItms[0] = new MenuItem();
mnuItms[0].Text = "开机自启动";
mnuItms[0].Click += new System.EventHandler(this.OpenStart);
}
mnuItms[0].DefaultItem = true;
mnuItms[1] = new MenuItem("-");
mnuItms[2] = new MenuItem();
mnuItms[2].Text = "打印机配置";
mnuItms[2].Click += new System.EventHandler(this.showmessage);
mnuItms[2].DefaultItem = true;
mnuItms[3] = new MenuItem("-");
//mnuItms[4] = new MenuItem();
//mnuItms[4].Text = "条码配置";
//mnuItms[4].Click += new System.EventHandler(this.Print_BarCode_Config);
//mnuItms[4].DefaultItem = true;
//mnuItms[5] = new MenuItem("-");
mnuItms[4] = new MenuItem();
mnuItms[4].Text = "退出系统";
mnuItms[4].Click += new System.EventHandler(this.ExitSelect);
mnuItms[4].DefaultItem = true;
TrayIcon.Visible = true;
TrayIcon.Click += new System.EventHandler(this.click);
notifyiconMnu = new ContextMenu(mnuItms);
TrayIcon.ContextMenu = notifyiconMnu;
//为托盘程序加入设定好的ContextMenu对象
}