我正在创建一个 Windows 应用程序。在此应用程序中,我使用 notifyicon
并将我的应用程序最小化到系统托盘。在我点击按钮的代码中,我在后台处理一些东西并每 2 秒返回一个整数值。我需要在 Notifyicon
上显示值。
谁能帮帮我???
最佳答案
尝试 NotifyIcon.ShowBalloonTip
方法:
Displays a balloon tip with the specified title, text, and icon in the taskbar for the specified time period.
void Form1_DoubleClick(object sender, EventArgs e)
{
notifyIcon1.Visible = true;
notifyIcon1.ShowBalloonTip(20000, "Information", "This is the text",
ToolTipIcon.Info );
}
如果要更改托盘图标,请按需创建一个图标并将其设置为 NotifyIcon.Icon
:
要创建图标,您可以使用以下代码(更新):
public static Icon GetIcon(string text)
{
Bitmap bitmap = new Bitmap(32, 32);
Icon icon = SmsSender.Properties.Resources.notifficationicon;
System.Drawing.Font drawFont = new System.Drawing.Font("Calibri", 16, FontStyle.Bold);
System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage(bitmap);
graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.SingleBitPerPixel;
graphics.DrawIcon(icon, 0, 0);
graphics.DrawString(text, drawFont, drawBrush, 1, 2);
Icon createdIcon = Icon.FromHandle(bitmap.GetHicon());
drawFont.Dispose();
drawBrush.Dispose();
graphics.Dispose();
bitmap.Dispose();
return createdIcon;
}
查看同一个项目:
关于c# - 在 Windows 应用程序中的 notifyicon 图标上显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12577749/