Title: Display system metrics with descriptions in C#
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 to experiment with it and to see additional details.