|
/// <summary>
/// A class which derived from the RadialGauge control.
/// </summary>
public class AdvancedRadialGauge : RadialGauge
{
CustomRenderer custom;
/// <summary>
/// Constructor
/// </summary>
public AdvancedRadialGauge()
{
custom = new CustomRenderer(this);
this.Renderer = custom;
}
// Local variable which holding the length of the needle.
private int needleLength = 60;
/// <summary>
/// Gets or sets the NeedleLength value
/// </summary>
public int NeedleLength
{
get { return needleLength; }
set { needleLength = value; }
}
}
|
|
/// <summary>
/// Custom renderer class
/// </summary>
public class CustomRenderer : IRadialGaugeRenderer
{
/// <summary>
/// Updates the renderer method.
/// </summary>
/// <param name="e"></param>
public void UpdateRenderer(PaintEventArgs e)
{
AdjustFontBounds(e.Graphics, RadialGauge.Font);
DrawOuterArc(e.Graphics, 135, 270, new Point(140, 140), 118);
// Draw Needle used to draw the Needle with the specified needle length
DrawNeedle(e.Graphics, 135, 270, m_RadialGauge.NeedleLength, 4, new Point(140, 140));
DrawGaugeLabel(e.Graphics, new Point(140, 140), 118);
DrawTickMarks(e.Graphics, new System.Drawing.Drawing2D.GraphicsPath(), 121, 135, 270, 4, new Point(140, 140), 95);
}
public void DrawNeedle(Graphics graphics, Int32 m_GaugeArcStart, Int32 m_GaugeArcEnd, Int32 m_NeedleRadius, Int32 m_NeedleWidth, Point m_Center)
{
Single brushAngle = (Int32)(m_GaugeArcStart + (RadialGauge.Value - RadialGauge.MinimumValue) * m_GaugeArcEnd / (RadialGauge.MaximumValue - RadialGauge.MinimumValue)) % 360;
Double needleAngle = brushAngle * Math.PI / 180;
if (RadialGauge.ShowNeedle)
{
Point startPoint = new Point((Int32)(m_Center.X - m_NeedleRadius / 8 * Math.Cos(needleAngle)),
(Int32)(m_Center.Y - m_NeedleRadius / 8 * Math.Sin(needleAngle)));
Point endPoint = new Point((Int32)(m_Center.X + m_NeedleRadius * Math.Cos(needleAngle)),
(Int32)(m_Center.Y + m_NeedleRadius * Math.Sin(needleAngle)));
graphics.DrawLine(new Pen(this.RadialGauge.NeedleColor, 3), m_Center.X, m_Center.Y, endPoint.X, endPoint.Y);
graphics.FillEllipse(new SolidBrush(this.RadialGauge.NeedleColor), m_Center.X - m_NeedleWidth * 3, m_Center.Y - m_NeedleWidth * 3, m_NeedleWidth * 6, m_NeedleWidth * 6);
}
}
} |