# Gauge with negative minimum value

I am having a little bit of trouble with the gauge and negative minimum values for the scale.

Modify the InstrumentDemo sample and in the file knobmeter.cs set:

``````     scale.Maximum = 100;
scale.Minimum = -100;
``````

Run the sample, notice the erratic behavior of the knob when moving the mouse. If the scale.Minimum is set to a value >=0, it works correctly.

What am I missing?

Wagner

That’s a bug. Thanks for reporting this. Here’s a GraduatedScaleElliptical class that fixes this:
[Serializable]
public override bool IntersectionWithLine(PointF p1, PointF p2, out double val) {
PointF q = new PointF();
if (this.Width < 1) {
GoStroke.NearestIntersectionOnLine(this.Position, new PointF(this.Left, this.Top + this.Height), p1, p2, out q);
} else if (this.Height < 1) {
GoStroke.NearestIntersectionOnLine(this.Position, new PointF(this.Left + this.Width, this.Top), p1, p2, out q);
} else {
GoEllipse.NearestIntersectionOnEllipse(this.Bounds, p2, p1, out q);
}
float theta = GoStroke.GetAngle(q.X - this.Center.X, q.Y - this.Center.Y);
float sa = this.StartAngle;
float sw = this.SweepAngle;
if (sw > 0) {
if (sw + sa > 360) {
if (theta >= sa || theta <= (sa + sw - 360)) {
val = GetValueForAngle(theta, sa, sw);
return true;
} else {
if (sa - theta < theta - (sa + sw - 360))
val = this.Minimum;
else
val = this.Maximum;
return false;
}
} else {
if (theta >= sa && theta <= sa + sw) {
val = GetValueForAngle(theta, sa, sw);
return true;
} else {
if (sa - theta < theta - (sa + sw - 360))
val = this.Minimum;
else
val = this.Maximum;
return false;
}
}
} else {
if (theta > sa)
theta -= 360;
if (theta <= sa && theta >= sa + sw) {
val = GetValueForAngle(theta, sa, sw);
return true;
} else {
if (Math.Min(Math.Abs(theta - sa), Math.Abs(theta - sa + 360)) < (sa + sw) - theta)
val = this.Minimum;
else
val = this.Maximum;
return false;
}
}
}
private double GetValueForAngle(float theta, float sa, float sw) {
if (theta < sa && sw > 0)
theta += 360;
if (theta > sa && sw < 0)
theta -= 360;
return ((theta - sa) / sw) * this.Range + this.Minimum;
}
}