[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Display system metrics 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."); ... AddValue(SystemMetric.SM_REMOTECONTROL, "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.SubItems.Add(GetSystemMetrics(metric).ToString()); item.SubItems.Add(descr); 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.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.