How To: Create a Linear Gauge (Runtime)

  • 2 minutes to read

The following example shows how to create a linear gauge.

In the example a linear gauge is created using the DevExpress.XtraGauges.Win.GaugeControlBase.AddLinearGauge method. The default elements (a scale, background layer and level bar) are added to the linear gauge via the LinearGauge.AddDefaultElements method. Then, some of them are customized in a specific manner.

The result is displayed below:


using DevExpress.XtraGauges.Win;
using DevExpress.XtraGauges.Win.Gauges.Linear;
using DevExpress.XtraGauges.Core.Model;
using DevExpress.XtraGauges.Core.Base;

GaugeControl gc = new GaugeControl();
// Add a linear gauge.
LinearGauge linearGauge = gc.AddLinearGauge();
// Add the default elements (a scale, background layer and level bar).
// Change the background layer's paint style.
LinearScaleBackgroundLayer background = linearGauge.BackgroundLayers[0];
background.ShapeType = BackgroundLayerShapeType.Linear_Style3;
// Customize the scale's settings.
LinearScaleComponent scale = linearGauge.Scales[0];
scale.MinValue = 0;
scale.MaxValue = 100;
scale.Value = 20;
scale.MajorTickCount = 6;
scale.MajorTickmark.FormatString = "{0:F0}";
scale.MajorTickmark.ShapeType = TickmarkShapeType.Linear_Style6_3;
scale.MinorTickCount = 3;
scale.MinorTickmark.ShapeType = TickmarkShapeType.Linear_Style5_2;          
// Shift tick marks to the right.
scale.MajorTickmark.ShapeOffset = 5f;
scale.MinorTickmark.ShapeOffset = 5f;
// Change the levelBar's paint style.
LinearScaleLevelComponent levelBar = linearGauge.Levels[0];
levelBar.ShapeType = LevelShapeSetType.Style3;
// Shift the background layer up and to the left.
background.ScaleStartPos = new PointF2D(background.ScaleStartPos.X - 0.005f,
    background.ScaleStartPos.Y - 0.015f);
background.ScaleEndPos = new PointF2D(background.ScaleEndPos.X - 0.005f, 
// Add the gauge control to the form.
gc.Size = new Size(250, 250);
gc.Parent = this;