我正在创建一个Windows应用程序。在这个应用程序中,我正在使用notifyicon
并将我的应用程序最小化到系统托盘。在我点击按钮的代码中,我在后台处理一些事情并每2秒返回一个整数值。我需要在Notifyicon
上显示值。
任何人都可以帮助我吗?
答案 0 :(得分:9)
尝试NotifyIcon.ShowBalloonTip
方法:
在指定的时间段内在任务栏中显示带有指定标题,文字和图标的气球提示。
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;
}
看到同样的项目:
答案 1 :(得分:2)
试试这个。希望这会对你有所帮助。
http://www.dotnetperls.com/notifyicon
http://www.codeproject.com/Articles/37451/Display-Progress-and-Overlay-Icons-for-Multiple-Vi
你可以做的最多这样的事情。
Graphics canvas;
Bitmap iconBitmap = new Bitmap(16, 16);
canvas = Graphics.FromImage(iconBitmap);
canvas.DrawIcon(YourProject.Resources.YourIcon, 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.Icon = Icon.FromHandle(iconBitmap.GetHicon());