Click here to Skip to main content
Click here to Skip to main content

A Cool Vista Sidebar Gadget Style CPUInfo Animate Control! (Fixed)

, 8 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A Cool Vista Sidebar Gadget Style CPUInfo Animate Control! (Fixed)


This article introduces how to make a Vista style cool CPUInfo control with C#. This control can get a percentage of CPU and Memory of the current Windows system.


Microsoft provides a beautiful sidebar in the Vista System, so I want to make the same control with C#. Thanks to GDI+, you can find that it is very easy to do so.

Using the Code

The main class is the VistaCPUInfo class; it is inherited from the Usercontrol class:

// Main Class
public partial class VistaCPUInfo : UserControl

To get the percentage of CPU, use the following code:

if (pc == null) pc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
cpu = (float)pc.NextValue();  //This is the aim value!

To get the percentage of physical memory, use the following code:

//Memory Structure
public struct MEMORY_INFO
    public uint dwLength;
    public uint dwMemoryLoad;
    public uint dwTotalPhys;
    public uint dwAvailPhys;
    public uint dwTotalPageFile;
    public uint dwAvailPageFile;
    public uint dwTotalVirtual;
    public uint dwAvailVirtual;
MemInfo = new MEMORY_INFO();
GlobalMemoryStatus(ref  MemInfo);
mem = (float)MemInfo.dwMemoryLoad;    //This is the aim value!

Then, use GDI+ methods to draw the result:

void VistaCPUInfo_Paint(object sender, PaintEventArgs e)
    e.Graphics.TextRenderingHint = 
        (Image, (int)positionRect.X, (int)positionRect.Y, 198, 159);
        (positionRect.X + 68f, positionRect.Y + 82f);
    e.Graphics.DrawImage(ImageDial, -5, -49, 10, 98);
        (positionRect.X + 143f, positionRect.Y + 50f);
    e.Graphics.DrawImage(ImageDialSmall, -5, -35, 10, 70);
        (ImageDialDot, (int)positionRect.X, (int)positionRect.Y, 198, 150);
    RectangleF rect = new RectangleF((int)positionRect.X + 53, 
                        (int)positionRect.Y + 107, 35, 15);
    e.Graphics.DrawString(((int)percentOfCPU).ToString() + 
                    "%", textFont, textBrush, rect, format);
    rect = new RectangleF((int)positionRect.X + 127, 
                (int)positionRect.Y + 66, 35, 13);
    e.Graphics.DrawString(((int)percentOfMemory).ToString() + 
                    "%", textFont, textBrush, rect, format);
        (ImageGlass, (int)positionRect.X, (int)positionRect.Y, 198, 159);

Points of Interest

  • Developing with GDI+ and C# is an very interesting thing!
  • PNG format picture is very good for drawing alpha pics!
  • For more code samples, please visit this Web site.


  • 2008/1/8: First posted on
  • 2008/5/9: Modified by Davidwu: disabled the animation in designtime mode. (thanks to Johnny J.!)


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author


China China
No Biography provided

Comments and Discussions

Generalthanks Pinmemberjishadshajahan21-May-13 2:51 
Generalvery nice work ! PinmemberBillWoodruff4-Apr-08 17:42 
GeneralRe: very nice work ! [modified] PinmemberDavidwu8-May-08 22:18 
QuestionGreat! may I use it? PinmemberWin32nipuh11-Feb-08 20:55 
AnswerRe: Great! may I use it? PinmemberDavidwu13-Feb-08 21:01 
GeneralRe: Great! may I use it? PinmemberWin32nipuh13-Feb-08 21:24 
GeneralRe: Great! may I use it? PinmemberDavidwu14-Feb-08 16:29 
GeneralI have thought of doing this meter control before PinmemberWong Shao Voon4-Feb-08 18:22 
GeneralRe: I have thought of doing this meter control before PinmemberDavidwu10-Feb-08 2:52 
GeneralA Tip for you... (applies to both your clock control and the CPU Info control here) PinmemberJohnny J.4-Feb-08 0:00 
GeneralRe: A Tip for you... (applies to both your clock control and the CPU Info control here) PinmemberDavidwu10-Feb-08 2:48 
GeneralWow Pinmember Dr.Luiji 3-Feb-08 21:58 
GeneralRe: Wow PinmemberDavidwu10-Feb-08 2:44 
GeneralContext menu items checked properties not updated PinmemberDaveyM6924-Jan-08 0:13 
GeneralRe: Context menu items checked properties not updated PinmemberDavidwu27-Jan-08 11:21 
QuestionIs the URL necessary? PinmemberMark Nischalke23-Jan-08 6:29 
AnswerRe: Is the URL necessary? PinmemberDavidwu23-Jan-08 7:49 
AnswerRe: Is the URL necessary? PinmemberHerbert Sauro18-Aug-08 19:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150129.1 | Last Updated 9 May 2008
Article Copyright 2008 by Davidwu
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid