开发者

How can I make a changing numerical value for a taskbar icon in C#?

开发者 https://www.devze.com 2022-12-30 21:48 出处:网络
I\'m trying to make a program in C# that monitors the processor time of an application. I\'d like to have a feature in this program where the task-bar icon is actually a number representing the proces

I'm trying to make a program in C# that monitors the processor time of an application. I'd like to have a feature in this program where the task-bar icon is actually a number representing the processor time (like what coretemp 开发者_Go百科has). How would I go about doing something like this?


You need to use the classes in the System.Drawing namespace.

Create a Bitmap, use Graphics.FromImage to draw on it, then call Icon.FromHandle(myBitmap.GetHicon()).
You can then set the icon as your form's Icon property.

EDIT: Like this:

using (var image = new Bitmap(16, 16)) 
using (var g = Graphics.FromImage(image)) {
    g.DrawString(...);
    myForm.Icon = Icon.FromHandle(image.GetHicon());
}

You can run this in a timer to continually update the icon.

You can get the CPU usage like this:

int usage;
using (var cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total")) {
    cpu.NextValue();            //First value is 0
    usage = cpu.NextValue();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消