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 に答える