Vista Glass Effect NotifyIcon CPU / Memory Meter

Some easy modifications to somebody's nice CPU / Memory Control to enable appearance in the Notification Area with mouseover CPU / Memory readings.

David Wu at http://www.cnpopsoft.com wrote a really nice "Vista CPU" glass effect UserControl for Windows Forms. I don't know about you, but I don't run the Windows Vista Sidebar any longer - it's a memory hog, and I've got enough problems making the OS from Hell behave without all the extras.

But one thing I really did like about the Sidebar was the CPU / Memory Gadget. Unfortunately it will only run if the Sidebar is running. That's why when I saw Wu's control project the first thing that sprung into my mind was to see if I could make it into a Notification Area "thingy" that would not only display the current Memory and CPU usage on mouse hover, but also would popup into a draggable UI control if you wanted it to.

Turns out that with the simple addition of a NotifyIcon control and some minor modifications and event handling, it's a piece of cake.

Here's a look first at the UI of the control in a semi-transparent Form container:

And here is (more or less) what I did in the Form to enable all this:




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace CNPOPSOFT.Controls
{
    public partial class frmMeter : Form
    {
        public frmMeter()
        {
            InitializeComponent();
        }

        private void frmMeter_Load(object sender, EventArgs e)
        {

        }

        private void Form1_Resize(object sender, System.EventArgs e)
        {
            // Hide if minimized
            if (FormWindowState.Minimized == WindowState)
                Hide();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {  
            // Show meter when notifyIcon is clicked in notification area
             Show();
            WindowState = FormWindowState.Normal;
        }

        private void vistaCPUInfo1_Load(object sender, EventArgs e)
        {

        }

        private void vistaCPUInfo1_Click(object sender, EventArgs e)
        {      
            // hide meter when clicked
            this.Hide();
        }

        

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            // Exit when Close menu item clicked
            Application.Exit();
        }

        private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // Re-show meter when Restore menu Item clicked
            this.WindowState = FormWindowState.Normal;
            this.Show();
        }

        private void notifyIcon1_MouseMove(object sender, MouseEventArgs e)
        {
            // show CPU and MEM details on mouse hover tooltip from notification area
            notifyIcon1.Text = "Cpu: "+vistaCPUInfo1.Cpu + " Mem: " + vistaCPUInfo1.Mem;
        }

        private void frmMeter_Click(object sender, EventArgs e)
        {
            // Hide when meter form clicked
            this.Hide();
        }
    }
}
There were also a couple of modifications to the Control class, but they were extremely simple - I just created two public fields for the Cpu and Mem readings so that it would be easy for the NotifyIcon to read these and display them when you mouse over the icon in the Notification Area. When you run the control app, it shows the full UI as above on your desktop, and you can drag it anywhere you want. There is also a context menu "Skin" on the control that allows you to switch between the Classic (above) skin and a "Black" skin.

When you click the control, it automatically minimizes to the Notification Area. A context menu allows you to Restore it, or Close it.  Have fun!

The Visual Studio 2008 Solution can be downloaded here.
By Peter Bromberg   Popularity  (2302 Views)