Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / WinForms

Customizable Tracker Control

4.64/5 (14 votes)
6 Jun 2010CPOL3 min read 30.7K   1K  
Windows Forms Control to visualize performance counters
tracker_demo.jpg

Introduction

A while ago, I stumbled over an article written by Andelko Pavelic. I looked into the code and found it to be an interesting approach. But I needed something more stable, accurate and flexible - and I needed better looks. So I took the base idea and wrote my own version, the TrackerControl 2.0. Although almost nothing is left of Andelko's initial code, credits belong to him for providing the initial idea.

Using the Code

There is a bunch of additional features and properties added to the original control.

First of all, the coloring of the drawn graph is extended to optionally use a linear color gradient:

tracker1.jpg

To make it more plastic, the area underneath the graph can be colorized:

tracker2.jpg

The grid can be adjusted in mesh size and optionally horizontal and/or vertical grid lines can be blanked:

tracker3.jpg

The wider the control, the more values are represented by the graph. I found it helpful in some cases to visualize the average as a horizontal bar:

tracker4.jpg

The average bar's color can also be set to a linear gradient, other than the one of the graph.

There are some features that can hardly be shown with still pictures, such as:

GridMovement.MoveWithGraph and GridMovement.Fixed

The grid can progressively move with the graph or stay fixed in the background.

GraphSizeMode.Fixed

This is the classic mode, known from the Windows Task Manager.

GraphSizeMode.Zoom

While still in line with values between Minimum and Maximum and colorizing the graph according to these fixed bounds, the vertical zoom level is continuously adjusted to the highest displayed value. That gives more granularity during periods of low values at a constant control height. The distance between the horizontal grid lines is adjusted as well (if shown), according to the zoom level.

GraphSizeMode.AutoAdjustMaximum

Sometimes the exact Maximum isn't known and it would be laborious to manually adjust the controls Maximum in your code during runtime. This setting does exactly that, correcting the Control's internal maximum continuously to the highest shown value. In difference to GraphSizeMode.Zoom, the graph's color gradient is fully utilized. The Maximum value in AutoAdjustMaximum acts as the initial internal maximum and also as the internal lower bound for its auto adjustment.

TrackerRefreshInDesignMode, TrackerRefreshInRuntimeMode and TrackerRefreshStartOnFirstValue

These settings do exactly as the names imply: The first one eventually saves you from headache caused by watching moving grid lines while designing the form and the second is useful to halt and resume the TrackerControl during runtime. The third prevents the Control from refreshing until it gets the first value to be drawn.

StartValue

Depending on the area of application, sometimes the start value of the graph needs to be other than 0.

ResetValueBuffer

Flushes the internal value buffer and clears the graph.

Points of Interest

Combining the settings help to customize visualization. They can also be changed during runtime, allowing interesting visual effects.

Keep in mind that there is no error handling implemented. Eventually, you need to do this yourself according to your application's exception handling strategy.

History

  • 6th June, 2010: Initial post

License

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