簡體   English   中英

在Windows應用程序中的notifyicon圖標上顯示文本

[英]Display Text over notifyicon icon in windows application

我正在創建一個Windows應用程序。 在這個應用程序中,我使用notifyicon並將我的應用程序最小化到系統托盤。 在我點擊按鈕的代碼中,我在后台處理一些事情並每2秒返回一個整數值。 我需要在Notifyicon上顯示Value。

誰能幫我???

嘗試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;
} 

看到同樣的項目:

試試這個吧。 希望這會對你有所幫助。

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());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM