Skip to main content

Gauge Class

NuGet: GHIElectronics.TinyCLR.UI
Assembly: GHIElectronics.TinyCLR.UI
Namespace: GHIElectronics.TinyCLR.UI.Controls

Analog gauge with calibrated tick marks, optional threshold arc, optional seven-segment digital readout, dial label, and pointer needle. Always square — pass the side length to the constructor. Rendering is cached: the static background (dial face, calibration, threshold, digital number, label) is drawn once into a backing bitmap; only the pointer is redrawn each paint. Any property change marks the background dirty.

public class Gauge : Image, IDisposable

Constructors​

Gauge(int side)​

public Gauge(int side) : base()

Creates a new square Gauge with the given side length in pixels.

Properties​

Font​

public Font Font { get; set; }

Font used for the dial labels and digital readout.

EnableDigitalNumber​

public bool EnableDigitalNumber { get; set; }

When true, a seven-segment digital value is shown below the dial.

EnableThreshold​

public bool EnableThreshold { get; set; }

When true, the threshold arc around the recommended value is drawn.

EnableScale​

public bool EnableScale { get; set; }

When true (the default), the control draws the tick marks and scale numbers. Set false when the dial face is supplied as a BackgroundImage that already includes the scale, so the control draws only the needle over your artwork (no numbers on top).

NeedleLength​

public double NeedleLength { get; set; }

Length of the pointer needle as a fraction of the dial radius (half the control size). Default 0.68 (the classic length). Lower = shorter needle — handy when a BackgroundImage dial's scale sits well inside the control. Clamped 0.1–1.2.

NeedleCenterY​

public double NeedleCenterY { get; set; }

Vertical position of the needle pivot (and centre cap) as a fraction of the control height. Default 0.5 (centre). Raise toward 1.0 (e.g. 0.75) to drop the pivot to the BOTTOM — the natural hub for a half (180°) dial whose arc sits in the upper area. Clamped 0–1. Affects only the needle/cap, so it's meant for an image-faced gauge (EnableScale=false); with drawn ticks it would offset the needle from the (centred) scale.

SweepAngle​

public float SweepAngle { get; set; }

Sweep of the dial arc in degrees (30–360). 270 (default) = classic dial, 180 = half dial, 360 = full ring. The arc is centred on the bottom opening.

StartPosition​

public GaugeStartPosition StartPosition { get; set; }

Which side the dial's OPENING (the gap between the low and high ends of the scale) sits on. Default GaugeStartPosition.Bottom (6 o'clock, the classic dial); Left = 9 o'clock, Top = 12 o'clock, Right = 3 o'clock. Rotates the whole dial together (arc, needle, ticks and labels).

BackColor​

public MediaColor BackColor { get; set; }

Background color behind the dial.

DialColor​

public MediaColor DialColor { get; set; }

Color of the dial face.

ForeColor​

public MediaColor ForeColor { get; set; }

Color of the tick marks, labels and dial text.

MinValue​

public float MinValue { get; set; }

Smallest value on the dial.

MaxValue​

public float MaxValue { get; set; }

Largest value on the dial.

ThresholdPercent​

public float ThresholdPercent { get; set; }

Threshold area around the recommended value, 1–99%.

RecommendedValue​

public float RecommendedValue { get; set; }

Value the threshold arc is centered on.

Value​

public float Value { get; set; }

Current needle position. Only this property doesn't dirty the background — the pointer is repainted every frame.

Glossiness​

public float Glossiness { get; set; }

Glossiness strength 0..100 (mapped to 0..220 alpha internally).

NoOfDivisions​

public int NoOfDivisions { get; set; }

Number of major tick divisions on the dial (2-24).

NoOfSubDivisions​

public int NoOfSubDivisions { get; set; }

Number of minor tick marks between major divisions (1-10).

DialText​

public string DialText { get; set; }

Label text drawn on the dial face.

EnableTransparentBackground​

public bool EnableTransparentBackground { get; set; }

When true, the dial face is overlapped by a slightly larger ellipse in the back color so the dial appears to float. Costs an extra FillEllipse per redraw.

BackgroundImage​

public System.Drawing.Image BackgroundImage { get; set; }

Optional custom dial-face image, drawn scaled to the square dial in place of the flat DialColor face. The tick marks, labels, threshold and needle are still drawn on top. Use with TransparentColor to key out a colour so a rectangular image can present as a circular (or any) shaped gauge.

TransparentColor​

public new MediaColor TransparentColor { get; set; }

A colour in BackgroundImage to make transparent (so a rectangular source image can show as a circular / custom-shaped gauge). Mirrors System.Drawing.Image.MakeTransparent; applied once when the background is next redrawn.

Methods​

Dispose()​

public void Dispose()

Releases the resources used by the gauge.

Dispose(bool disposing)​

protected virtual void Dispose(bool disposing)

Releases the gauge's cached drawing surfaces.

OnRender(DrawingContext dc)​

public override void OnRender(DrawingContext dc)

Draws the dial face and pointer needle.