请提供一些意见.谢谢
我为Tray构建了CustomApplicationContent.下面的一些片段:
Program.cs中
[STAThread] static voID Main() { if (!SingleInstance.Start()) { return; } Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { var applicationContext = new CustomApplicationContext(); Application.Run(applicationContext); } catch (Exception ex) { MessageBox.Show(ex.Message,"Program Terminated Unexpectedly",MessageBoxbuttons.OK,MessageBoxIcon.Error); } SingleInstance.Stop(); }
CustomApplicationContext.cs
public class CustomApplicationContext : ApplicationContext{ private System.ComponentModel.IContainer components; // a List of components to dispose when the context is disposed private NotifyIcon notifyIcon; private static Readonly string Iconfilename = "green.ico"; private static Readonly string Defaulttooltip = "Employee Management System"; private Readonly TrayManager trayManager; public CustomApplicationContext() { InitializeContext(); trayManager = new TrayManager(notifyIcon); } protected overrIDe voID dispose(bool disposing) { if (disposing && components != null) { components.dispose(); } } private voID InitializeContext() { components = new System.ComponentModel.Container(); notifyIcon = new NotifyIcon(components) { ContextMenuStrip = new ContextMenuStrip(),Icon = new Icon(Iconfilename),Text = Defaulttooltip,Visible = true }; notifyIcon.ContextMenuStrip.opening += ContextMenuStrip_opening; notifyIcon.DoubleClick += notifyIcon_DoubleClick; //notifyIcon.MouseUp += notifyIcon_MouseUp; }private voID notifyIcon_DoubleClick(object sender,EventArgs e) { ShowAboutForm(); }private TestForm testForm; private voID ShowAboutForm() { if (testForm == null) { testForm = new TestForm { trayManager = trayManager }; testForm.Closed += testForm_Closed; ; // avoID reshowing a disposed form testForm.Show(); } else { testForm.Activate(); } } voID testForm_Closed(object sender,EventArgs e) { testForm = null; }
我在哪里添加计时器 – 在上下文中?用户可能无法打开表单,因此在表单上添加计时器可能无法一直运行.如何更改图标?
@R_301_6120@ 我将创建您的Icons Embedded Resources,然后使用这样的代码在运行时更改当前显示的代码:notifyIcon.Icon = new Icon(this.GetType(),"red.ico");总结
以上是内存溢出为你收集整理的c# – 更改系统托盘图标图像全部内容,希望文章能够帮你解决c# – 更改系统托盘图标图像所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)