Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI
This Document is not yet Rated  Rate this Document

Multiple Pointers on Measurement Studio Gauge or Meter

Primary Software: Measurement Studio>>.NET Support
Primary Software Version: 7.0
Primary Software Fixed Version: N/A
Secondary Software: N/A

Problem: I would like to have multiple pointers for a gauge or a meter in a Measurement Studio application, but I do not see an option for it. Is there any way to add pointers?

Solution: The default gauge and meter classes do not have the ability to have multiple pointers, however you can derive classes that do have this ability. This derived class must expose two properties for each pointer, one for the color and one for the value. The following code is a class for a gauge with a second pointer which is used for the maximum value that the gauge reaches. After this class is in your application, you use it by changing the line in InitializeComponent to instantiate the MultiplePointerGauge class instead of the Gauge class. The good news is that you can still use the property pages in the designer to modify the gauge. If more pointers are necessary or you need multiple pointers on a gauge, you can use the same process.


public class MultiplePointerGauge : Gauge
{
private double _maxPointerValue;
private Color _maxPointerColor;

public MultiplePointerGauge() : base()
{
GaugeStyle = new MultiplePointersStyle();
_maxPointerColor = PointerColor;
_maxPointerValue = Value;
}

public Color MaxPointerColor
{
get
{
return _maxPointerColor;
}
set
{
_maxPointerColor = value;
Invalidate();
}
}

public double MaxPointerValue
{
get
{
return _maxPointerValue;
}
set
{
_maxPointerValue = value;
Invalidate();
}
}

private class MultiplePointersStyle : GaugeStyle
{
private GaugeStyle _baseStyle;

public MultiplePointersStyle() : this(GaugeStyle.SunkenWithThickNeedle3D)
{
}

public MultiplePointersStyle(GaugeStyle baseStyle)
{
if(baseStyle == null)
throw new ArgumentNullException("baseStyle");

_baseStyle = baseStyle;
}

public override void DrawSpindle(IGauge context, RadialNumericPointerStyleDrawArgs args)
{
_baseStyle.DrawSpindle(context, args);
}

public override float GetDialRadius(IRadialNumericPointer context,
Graphics graphics, Rectangle bounds)
{
return _baseStyle.GetDialRadius(context, graphics, bounds);
}

public override void DrawDial(IRadialNumericPointer context,
RadialNumericPointerStyleDrawArgs args)
{
_baseStyle.DrawDial(context, args);
}

public override RadialNumericPointerHitTestInfo HitTest(IRadialNumericPointer context,
Rectangle bounds, int x, int y)
{
return _baseStyle.HitTest(context, bounds, x, y);
}

public override void DrawPointer(INumericPointer context,
NumericPointerStyleDrawArgs args, double value)
{
MultiplePointerGauge gauge = context as MultiplePointerGauge;

Color defaultColor = context.PointerColor;
_baseStyle.DrawPointer(context, args, value);

context.PointerColor = gauge.MaxPointerColor;
_baseStyle.DrawPointer(context, args, gauge.MaxPointerValue);
context.PointerColor = defaultColor;
}

public override float GetScaleRadius(IRadialNumericPointer context,
Graphics graphics, Rectangle bounds)
{
return _baseStyle.GetScaleRadius (context, graphics, bounds);
}
}
}


Related Links: Measurement Studio Support

Attachments:





Report Date: 11/13/2005
Last Updated: 11/21/2005
Document ID: 3RCIQ89F

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
  1 2 3 4 5
Please Contact NI for all product and support inquiries.submit