Charting for WinForms Programmer's Guide
Pointers

The pointers represent needles or similar type of indicators within the scale. They are used to visualize a current measurement within the scale. The most important member of the pointer object is its Value. The pointer is automatically adjusted by its containing scale so that it points to the scale location, corresponding to its value.

The size of the pointer is defined by the PointerWidth and PointerHeight properties. These properties can express the size as relative or absolute value. The location of the pointer can be adjusted through the PointerOffset property and its alignment in a linear scale can be specified through the Alignment property.

The pointer can be made interactive by setting the IsInteractive property to true. Clicking with the mouse within a scale causes all its interactive pointers to be adjusted to the value corresponding to the clicked point. A pointer can be made discrete by setting IsDiscrete to true. The value of a discrete pointer is always integer.

Usage

The sample code below illustrates how to define and add pointers to an existing scale:

C#  Copy Code

scale.Pointers.Add(new Pointer() { IsInteractive = true });

Custom Appearance

The appearance of the pointer can be customized by using the PrepaintPointer and PaintPointer events. The following example demonstrates an oval gauge with a compass needle type of pointer:

C#  Copy Code

var ovalScale = new OvalScale();
ovalScale.Fill = new MindFusion.Drawing.SolidBrush(Color.Transparent);
ovalScale.Stroke = new MindFusion.Drawing.Pen(Color.Transparent);
ovalScale.MinValue = 0;
ovalScale.MaxValue = 360;
ovalScale.MajorTickSettings.ShowTicks = false;
ovalScale.MajorTickSettings.ShowLabels = false;
ovalScale.MiddleTickSettings.ShowTicks = false;
ovalScale.MiddleTickSettings.ShowLabels = false;

var pointer = new Pointer();
pointer.PointerWidth = new Length(200, LengthType.Relative);
pointer.PointerHeight = new Length(20, LengthType.Relative);
pointer.PointerOffset = new Length(90, LengthType.Relative);
pointer.IsInteractive = true;
ovalScale.Pointers.Add(pointer);

ovalGauge = new MindFusion.Gauges.WinForms.OvalGauge();
ovalGauge.Scales.Add(ovalScale);
ovalGauge.PrepaintPointer += (s, e) =>
{
    e.CancelDefaultPainting = true;

    var state = e.Graphics.Save();
    e.Graphics.ScaleTransform(e.Element.RenderSize.Width, e.Element.RenderSize.Height);

    var boundingRect = new RectangleF(0, 0, 1, 1);

    var commonStroke = new Pen(Color.FromArgb(255, 32, 32, 32), 0.015f);

    var pt1 = new PointF(0.5f, 0);
    var pt2 = new PointF(1, 0.5f);
    var pt3 = new PointF(0.5f, 1);
    var pt4 = new PointF(0, 0.5f);

    var fill1path = new GraphicsPath();
    fill1path.AddPolygon(new PointF[] { pt1, pt2, pt3 });

    var fill1 = new PathGradientBrush(fill1path);
    fill1.CenterPoint = new PointF(0.5f, 0);
    var fill1blend = new ColorBlend();
    fill1blend.Positions = new float[] { 0, 0.3f, 1 };
    fill1blend.Colors = new Color[]
    {
        Color.FromArgb(255, 193, 0, 0),
        Color.FromArgb(255, 255, 0, 0),
        Color.FromArgb(255, 102, 0, 0)
    };
    fill1.InterpolationColors = fill1blend;

    e.Graphics.FillPolygon(fill1, new PointF[] { pt1, pt2, pt3 });

    fill1path.AddPolygon(new PointF[] { pt1, pt4, pt3 });

    var fill2 = new PathGradientBrush(fill1path);
    fill2.CenterPoint = new PointF(0.5f, 0);
    var fill2blend = new ColorBlend();
    fill2blend.Positions = new float[] { 0, 0.3f, 1 };
    fill2blend.Colors = new Color[]
    {
        Color.FromArgb(255, 193, 193, 193),
        Color.FromArgb(255, 204, 204, 204),
        Color.FromArgb(255, 102, 102, 102)
    };
    fill2.InterpolationColors = fill2blend;

    e.Graphics.FillPolygon(fill2, new PointF[] { pt1, pt4, pt3 });

    e.Graphics.DrawPolygon(commonStroke, new PointF[] { pt1, pt2, pt3, pt4 });

    PointF center = new PointF(boundingRect.Width / 2, boundingRect.Height / 2);
    SizeF size = new SizeF(0.03f, 0.3f);

    e.Graphics.DrawEllipse(commonStroke, new RectangleF(new PointF(center.X - size.Width / 2f, center.Y - size.Height / 2f), size));
    e.Graphics.FillEllipse(new SolidBrush(Color.DimGray), new RectangleF(new PointF(center.X - size.Width / 2f, center.Y - size.Height / 2f), size));

    fill1.Dispose();
    fill2.Dispose();
    fill1path.Dispose();
    e.Graphics.Restore(state);
};

The above gauge will look similar to the following image: