5

我正在创建一个 Windows 应用程序。在这个应用程序中,我正在使用notifyicon并将我的应用程序最小化到系统托盘。在我的按钮单击代码中,我在后台处理一些事情并每 2 秒返回一个整数值。我需要在Notifyicon.

谁能帮我???

4

2 回答 2

11

尝试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;
} 

看到同样的项目:

于 2012-09-25T07:09:07.377 回答
3

试试这个。希望这对您有所帮助。

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());
于 2012-09-25T07:14:34.610 回答