Display system metric values with descriptions in C#

[system metrics]

The example Get system metrics in C# shows how to get system metrics, but the the metrics’ terse names make the results hard to understand. This example displays descriptions of the metrics in addition to their values.

Some of the descriptions are too long to fit nicely in a ListView column so the program sets the ListView items’ ToolTipText values to also show the descriptions. Even if you set those values, however, the ListView doesn’t display the items’ tooltips unless you set its ShowItemToolTips property to true. The program uses the following code to set that property and to initialize the ListView control’s values.

// Display some useful metrics.
private void Form1_Load(object sender, EventArgs e)
    lvwMetrics.ShowItemToolTips = true;

    AddValue(SystemMetric.SM_CXSCREEN, "Primary screen width.");
    AddValue(SystemMetric.SM_CYSCREEN, "Primary screen height.");
    AddValue(SystemMetric.SM_CXVSCROLL, "Width of vertical scroll bar.");
    AddValue(SystemMetric.SM_CYHSCROLL, "Height of horizontal scroll bar.");
    AddValue(SystemMetric.SM_CYCAPTION, "Height of caption area.");
        "Nonzero if the session is remotely controlled; zero otherwise.");

The following code shows the new AddValue method used by this example.

private void AddValue(SystemMetric metric, string descr)
    ListViewItem item = lvwMetrics.Items.Add(metric.ToString());
    item.ToolTipText = descr;

This code creates a ListView item, setting its text equal to the metric’s name. It adds the metric’s value and description as sub-items. It also sets the item’s ToolTipText property equal to the description.

Download the example and look at the code to see all 89 of the metrics and their descriptions.

Download Example   Follow me on Twitter   RSS feed   Donate

This entry was posted in API, system and tagged , , , , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.