我有以下代码“应该”在现有的托盘图标上绘制一个 2 但运行时图标不更新?我已将位图保存到文件中,并且确实按预期在顶部绘制了 2 个绘图,我是否需要以某种方式刷新托盘图标以使其更新,还是我以错误的方式进行此操作t_Elapsed:Graphics canvas;Bitmap iconBitmap = new Bitmap(16, 16);canvas = Graphics.FromImage(iconBitmap);canvas.DrawIcon(Properties.Resources.SystemTrayApp, 0, 0);StringFormat format = new StringFormat();format.Alignment = StringAlignment.Center;canvas.DrawString( "2", new Font("Calibri", 8, FontStyle.Bold), new SolidBrush(Color.FromArgb(40, 40, 40)), new RectangleF(0, 3, 16, 13), format);NotifyIcon ni;ni = new NotifyIcon();ni.Icon = Icon.FromHandle(iconBitmap.GetHicon());ni.Visible = true;t.Start();这是最初生成notifyicon的代码......namespace SystemTrayApp{class ProcessIcon : IDisposable{ NotifyIcon ni; public ProcessIcon() { ni = new NotifyIcon(); } public void Display() { ni.MouseClick += new MouseEventHandler(ni_MouseClick); ni.Icon = Resources.SystemTrayApp; ni.Text = "Auto Sort"; ni.Visible = true; ni.ContextMenuStrip = new ContextMenus().Create(); } public void Dispose() { ni.Dispose(); }}}这是调用初始 ProcessIcon 的主要部分。static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Show the system tray icon. using (ProcessIcon pi = new ProcessIcon()) { pi.Display(); t = new System.Timers.Timer(); t.AutoReset = false; t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed); t.Interval = 2000; t.Start(); // Make sure the application runs! Application.Run(); } }这个主要部分启动了你可以在第一部分看到的计时器循环,我正在尝试更新托盘图标但失败了(好吧,除了建议的现有图标之外,它还创建了一个新图标)定时器循环如何访问 pi 对象来更新图标?
- 1 回答
- 0 关注
- 191 浏览
添加回答
举报
0/150
提交
取消