DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,36 @@
namespace DevComponents.Instrumentation
{
partial class GaugeControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,543 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class GaugeControlItem
{
#region Private variables
private GaugeControl _GaugeControl;
private GaugeControlItem _Parent;
private GaugeFrame _GaugeFrame;
private GaugeScaleCollection _GaugeScaleItems;
private GaugeImageCollection _GaugeImageItems;
private GaugeTextCollection _GaugeTextItems;
private int _SuspendCount;
private bool _NeedRecalcLayout;
private float _Height;
private float _Width;
private PointF _Location;
private PointF _PivotPoint;
private float _Radius;
private Rectangle _AbsBounds;
private bool _Visible;
#endregion
public GaugeControlItem()
{
_GaugeFrame = new GaugeFrame(this);
_GaugeScaleItems = new GaugeScaleCollection();
_Width = 1;
_Height = 1;
_PivotPoint = new PointF(.5f, .5f);
_Radius = .5f;
NeedRecalcLayout = true;
HookEvents(true);
}
#region Public properties
#region GaugeFrame
/// <summary>
/// Gets the Gauge Frame.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Gauge Frame.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GaugeFrame GaugeFrame
{
get { return (_GaugeFrame); }
}
#endregion
#region GaugeScaleItems
/// <summary>
/// Gets the collection GaugeScaleItems contained within the gauge.
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the collection GaugeScaleItems contained within the gauge.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GaugeScaleCollection GaugeScaleItems
{
get { return (_GaugeScaleItems); }
}
#endregion
#region Location
public PointF Location
{
get { return (_Location); }
set
{
if (_Location != value)
{
_Location = value;
OnGaugeChanged();
}
}
}
#endregion
#region Height
public float Height
{
get { return (_Height); }
set
{
if (_Height != value)
{
_Height = value;
OnResize(EventArgs.Empty);
}
}
}
#endregion
#region PivotPoint
public PointF PivotPoint
{
get { return (_PivotPoint); }
set
{
if (_PivotPoint.Equals(value) == false)
{
_PivotPoint = value;
OnGaugeChanged();
}
}
}
#endregion
#region Radius
public float Radius
{
get { return (_Radius); }
set
{
if (_Radius != value)
{
_Radius = value;
OnGaugeChanged();
}
}
}
#endregion
#region Visible
public bool Visible
{
get { return (_Visible); }
set
{
if (_Visible != value)
{
_Visible = value;
Refresh();
}
}
}
#endregion
#region Width
public float Width
{
get { return (_Width); }
set
{
if (_Width != value)
{
_Width = value;
OnResize(EventArgs.Empty);
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsBounds
internal Rectangle AbsBounds
{
get { return (_AbsBounds); }
}
#endregion
#region AbsHeight
internal int AbsHeight
{
get { return (_AbsBounds.Height); }
}
#endregion
#region AbsWidth
internal int AbsWidth
{
get { return (_AbsBounds.Width); }
}
#endregion
#region GaugeControl
internal GaugeControl GaugeControl
{
get { return (_GaugeControl); }
set { _GaugeControl = value; }
}
#endregion
#region NeedRecalcLayout
internal bool NeedRecalcLayout
{
get { return (_NeedRecalcLayout); }
set
{
_NeedRecalcLayout = value;
if (_NeedRecalcLayout == true)
OnLayoutChanged();
}
}
#endregion
#region Parent
internal GaugeControlItem Parent
{
get { return (_Parent); }
set { _Parent = value; }
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
{
_GaugeFrame.GaugeFrameChanged += GaugeFrame_GaugeFrameChanged;
}
else
{
_GaugeFrame.GaugeFrameChanged -= GaugeFrame_GaugeFrameChanged;
}
}
#endregion
#region Event processing
void GaugeFrame_GaugeFrameChanged(object sender, EventArgs e)
{
OnGaugeChanged();
}
#endregion
#region BeginUpdate
/// <summary>
/// Disables any redrawing of the Gauge control. To maintain performance while items
/// are added one at a time to the control, call the BeginUpdate method. The BeginUpdate
/// method prevents the control from painting until the
/// <see cref="EndUpdate">EndUpdate</see> method is called.
/// </summary>
public void BeginUpdate()
{
_SuspendCount++;
}
#endregion
#region EndUpdate
/// <summary>
/// Enables the redrawing of the Gauge control. To maintain performance while items are
/// added one at a time to the control, call the <see cref="BeginUpdate">BeginUpdate</see>
/// method. The BeginUpdate method prevents the control from painting until the EndUpdate
/// method is called.
/// </summary>
public void EndUpdate()
{
if (_SuspendCount > 0)
_SuspendCount--;
if (_SuspendCount == 0)
Refresh();
}
#endregion
#region Refresh
private void Refresh()
{
if (_GaugeControl != null)
_GaugeControl.Invalidate(_GaugeFrame.Bounds);
}
#endregion
#region RecalcLayout
private void RecalcLayout()
{
if (_NeedRecalcLayout == true)
{
NeedRecalcLayout = false;
_AbsBounds = GetItemBounds();
}
}
#endregion
#region GetItemBounds
private Rectangle GetItemBounds()
{
Rectangle r;
if (_Parent != null)
{
if (_Parent.NeedRecalcLayout == true)
throw new Exception();
r = _Parent.AbsBounds;
}
else
{
if (_GaugeControl == null)
throw new Exception();
r = _GaugeControl.Bounds;
}
if (_GaugeFrame.Style == GaugeFrameStyle.Circular)
{
int n = Math.Min(r.Width, r.Height);
int x = (r.Width - n) / 2;
int y = (r.Height - n) / 2;
n = Math.Max(n, 1);
r = new Rectangle(x, y, n, n);
}
else
{
r.X = (int)(r.Width * _Location.X);
r.Y = (int)(r.Height * _Location.Y);
r.Width = (int)(r.Width * _Width);
r.Height = (int)(r.Height * _Height);
}
return (r);
}
#endregion
#region OnLayoutChanged
private void OnLayoutChanged()
{
GaugeFrame.NeedRecalcLayout = true;
if (_GaugeScaleItems != null)
{
foreach (GaugeScale item in _GaugeScaleItems)
item.NeedRecalcLayout = true;
}
if (_GaugeImageItems != null)
{
foreach (GaugeImage item in _GaugeImageItems)
item.NeedRecalcLayout = true;
}
if (_GaugeTextItems != null)
{
foreach (GaugeText item in _GaugeTextItems)
item.NeedRecalcLayout = true;
}
}
#endregion
#region OnPaint
public void OnPaint(PaintEventArgs e)
{
RecalcLayout();
GaugeFrame.OnPaint(e);
PaintScaleItems(e);
PaintImageItems(e);
PaintTextItems(e);
}
#region PaintScaleItems
private void PaintScaleItems(PaintEventArgs e)
{
if (_GaugeScaleItems != null)
{
foreach (GaugeScale scale in _GaugeScaleItems)
{
if (scale.Visible == true)
scale.OnPaint(e);
}
}
}
#endregion
#region PaintImageItems
private void PaintImageItems(PaintEventArgs e)
{
if (_GaugeImageItems != null)
{
foreach (GaugeImage scale in _GaugeImageItems)
{
if (scale.Visible == true)
scale.OnPaint(e);
}
}
}
#endregion
#region PaintTextItems
private void PaintTextItems(PaintEventArgs e)
{
if (_GaugeTextItems != null)
{
foreach (GaugeText scale in _GaugeTextItems)
{
if (scale.Visible == true)
scale.OnPaint(e);
}
}
}
#endregion
#region GetAbsPoint
internal Point GetAbsPoint(PointF ptf)
{
if (NeedRecalcLayout == true)
throw new Exception();
return (new Point((int) (AbsWidth*ptf.X), (int) (AbsHeight*ptf.Y)));
}
#endregion
#region GetAbsSize
internal Size GetAbsSize(SizeF sf, bool useMin)
{
if (NeedRecalcLayout == true)
throw new Exception();
int width = AbsWidth;
int height = AbsHeight;
if (useMin == true)
{
if (width > height)
width = height;
else
height = width;
}
return (new Size((int)(width * sf.Width), (int)(height * sf.Height)));
}
#endregion
#endregion
#region OnResize
public void OnResize(EventArgs e)
{
NeedRecalcLayout = true;
}
#endregion
#region OnGaugeChanged
protected void OnGaugeChanged()
{
Refresh();
}
#endregion
}
}

View File

@@ -0,0 +1,360 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeFrameCircularRenderer : GaugeFrameRenderer
{
public GaugeFrameCircularRenderer(GaugeFrame gaugeFrame)
: base(gaugeFrame)
{
}
#region SetFrameRegion
internal override void SetFrameRegion()
{
if (GaugeFrame.GaugeControl != null)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(GaugeFrame.Bounds);
GaugeFrame.GaugeControl.Region = new Region(path);
}
}
}
#endregion
#region SetBackClipRegion
internal override void SetBackClipRegion(PaintEventArgs e)
{
int inside = GaugeFrame.AbsBevelInside;
int outside = GaugeFrame.AbsBevelOutside;
Rectangle r = GaugeFrame.Bounds;
r.Inflate(-outside -inside, -outside -inside);
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(r);
e.Graphics.SetClip(path, CombineMode.Intersect);
}
}
#endregion
#region RenderFrame
#region RenderFrameByAngle
protected override void RenderFrameByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
Matrix myMatrix = new Matrix();
myMatrix.RotateAt(GaugeFrame.FrameColor.GradientAngle, GaugeFrame.Center);
e.Graphics.Transform = myMatrix;
using (Brush br = GaugeFrame.FrameColor.GetBrush(GaugeFrame.Bounds, 0))
g.FillEllipse(br, GaugeFrame.Bounds);
RenderFrameBorder(g);
using (Brush br = GaugeFrame.FrameColor.GetBrush(r, 180))
g.FillEllipse(br, r);
g.ResetTransform();
}
#endregion
#region RenderFrameByCenter
protected override void RenderFrameByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(GaugeFrame.Bounds);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.End };
br.SetSigmaBellShape(GaugeFrame.FrameSigmaFocus, GaugeFrame.FrameSigmaScale);
g.FillEllipse(br, GaugeFrame.Bounds);
}
path.AddEllipse(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.End;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.Start };
g.FillEllipse(br, r);
}
}
RenderFrameBorder(g);
}
#endregion
#region PaintCircularFrameByHvCenter
protected override void RenderFrameByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 90);
}
protected override void RenderFrameByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 0);
}
private void RenderFrameByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = GaugeFrame.Bounds;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillEllipse(br, GaugeFrame.Bounds);
}
t = r;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle + 180))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillEllipse(br, r);
}
RenderFrameBorder(g);
}
#endregion
#region RenderFrameByNone
protected override void RenderFrameByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.Start))
g.FillEllipse(br, GaugeFrame.Bounds);
if (GaugeFrame.FrameColor.End.IsEmpty == false)
{
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.End))
g.FillEllipse(br, r);
}
RenderFrameBorder(g);
}
#endregion
#region RenderFrameBorder
private void RenderFrameBorder(Graphics g)
{
if (GaugeFrame.FrameColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.FrameColor.BorderColor, GaugeFrame.FrameColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawEllipse(pen, GaugeFrame.Bounds);
}
}
}
#endregion
#endregion
#region RenderrBack
#region RenderBackByAngle
protected override void RenderBackByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
Matrix myMatrix = new Matrix();
myMatrix.RotateAt(GaugeFrame.BackColor.GradientAngle, GaugeFrame.Center);
e.Graphics.Transform = myMatrix;
using (Brush br = GaugeFrame.BackColor.GetBrush(r, 0))
g.FillEllipse(br, r);
g.ResetTransform();
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByCenter
protected override void RenderBackByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = GaugeFrame.BackColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.BackColor.End };
br.CenterPoint = GaugeFrame.Center;
br.SetSigmaBellShape(GaugeFrame.BackSigmaFocus, GaugeFrame.BackSigmaScale);
g.FillRectangle(br, r);
}
}
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByHvCenter
protected override void RenderBackByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 90);
}
protected override void RenderBackByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 0);
}
private void RenderBackByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = r;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.BackColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillEllipse(br, r);
}
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByNone
protected override void RenderBackByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = new SolidBrush(GaugeFrame.BackColor.Start))
g.FillEllipse(br, r);
RenderBackBorder(g, r);
}
#endregion
#region RenderBackBorder
private void RenderBackBorder(Graphics g, Rectangle r)
{
if (GaugeFrame.BackColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.BackColor.BorderColor, GaugeFrame.BackColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawEllipse(pen, r);
}
}
}
#endregion
#endregion
#region PreRenderContent
internal override void PreRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 45);
}
#endregion
#region PostRenderContent
internal override void PostRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 90);
}
#endregion
#region AddGlassEffect
private void AddGlassEffect(PaintEventArgs e, float angle)
{
Graphics g = e.Graphics;
Rectangle r = GaugeFrame.BackBounds;
r.Height /= 2;
if (r.Height > 0)
{
Color color1 = Color.FromArgb(100, Color.White);
using (LinearGradientBrush br =
new LinearGradientBrush(r, color1, Color.Transparent, angle))
{
g.FillEllipse(br, r);
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,345 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeFrameRectangularRenderer : GaugeFrameRenderer
{
public GaugeFrameRectangularRenderer(GaugeFrame gaugeFrame)
: base(gaugeFrame)
{
}
#region SetBackClipRegion
internal override void SetBackClipRegion(PaintEventArgs e)
{
int inside = GaugeFrame.AbsBevelInside;
int outside = GaugeFrame.AbsBevelOutside;
Rectangle r = GaugeFrame.Bounds;
r.Inflate(-outside - inside, -outside - inside);
e.Graphics.SetClip(r, CombineMode.Intersect);
}
#endregion
#region RenderFrame
#region RenderFrameByAngle
protected override void RenderFrameByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = GaugeFrame.FrameColor.GetBrush(GaugeFrame.Bounds))
g.FillRectangle(br, GaugeFrame.Bounds);
using (Brush br = GaugeFrame.FrameColor.GetBrush(r, GaugeFrame.FrameColor.GradientAngle + 180))
g.FillRectangle(br, r);
RenderFrameBorder(g, GaugeFrame.Bounds);
}
#endregion
#region RenderFrameByCenter
protected override void RenderFrameByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(GaugeFrame.Bounds);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.End };
br.SetSigmaBellShape(GaugeFrame.FrameSigmaFocus, GaugeFrame.FrameSigmaScale);
g.FillRectangle(br, GaugeFrame.Bounds);
}
path.AddRectangle(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.End;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.Start };
g.FillRectangle(br, r);
}
}
RenderFrameBorder(g, GaugeFrame.Bounds);
}
#endregion
#region PaintCircularFrameByHvCenter
protected override void RenderFrameByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 90);
}
protected override void RenderFrameByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 0);
}
private void RenderFrameByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = GaugeFrame.Bounds;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, GaugeFrame.Bounds);
}
t = r;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle + 180))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
RenderFrameBorder(g, GaugeFrame.Bounds);
}
#endregion
#region RenderFrameByNone
protected override void RenderFrameByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.Start))
g.FillRectangle(br, GaugeFrame.Bounds);
if (GaugeFrame.FrameColor.End.IsEmpty == false)
{
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.End))
g.FillRectangle(br, r);
}
RenderFrameBorder(g, GaugeFrame.Bounds);
}
#endregion
#region RenderFrameBorder
private void RenderFrameBorder(Graphics g, Rectangle r)
{
if (GaugeFrame.FrameColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.FrameColor.BorderColor, GaugeFrame.FrameColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
r.Width--;
r.Height--;
g.DrawRectangle(pen, r);
}
}
}
#endregion
#endregion
#region RenderrBack
#region RenderBackByAngle
protected override void RenderBackByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = GaugeFrame.BackColor.GetBrush(r))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByCenter
protected override void RenderBackByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = GaugeFrame.BackColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.BackColor.End };
br.CenterPoint = GaugeFrame.Center;
br.SetSigmaBellShape(GaugeFrame.BackSigmaFocus, GaugeFrame.BackSigmaScale);
g.FillRectangle(br, r);
}
}
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByHvCenter
protected override void RenderBackByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 90);
}
protected override void RenderBackByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 0);
}
private void RenderBackByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = r;
t.Height /= 2;
t.Width /= 2;
using (Brush br = GaugeFrame.BackColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
RenderBackBorder(g, r);
}
#endregion
#region RenderBackByNone
protected override void RenderBackByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (Brush br = new SolidBrush(GaugeFrame.BackColor.Start))
g.FillRectangle(br, r);
RenderBackBorder(g, r);
}
#endregion
#region RenderBackBorder
private void RenderBackBorder(Graphics g, Rectangle r)
{
if (GaugeFrame.BackColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.BackColor.BorderColor, GaugeFrame.BackColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
r.Width--;
r.Height--;
g.DrawRectangle(pen, r);
}
}
}
#endregion
#endregion
#region PreRenderContent
internal override void PreRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 2.5f, 45);
}
#endregion
#region PostRenderContent
internal override void PostRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 2, 90);
}
#endregion
#region AddGlassEffect
private void AddGlassEffect(PaintEventArgs e, float f, float angle)
{
Graphics g = e.Graphics;
Rectangle r = GaugeFrame.BackBounds;
float x = Math.Max(r.Height, r.Width);
using (GraphicsPath path = new GraphicsPath())
{
path.AddLines(new Point[] {
new Point(r.X, r.Y),
new Point(r.X, (int)(r.Y + x / f)),
new Point(r.X + (int)(x / f), r.Y)});
path.CloseFigure();
Color color1 = Color.FromArgb(40, Color.White);
using (LinearGradientBrush br =
new LinearGradientBrush(r, color1, Color.Transparent, angle))
{
g.FillPath(br, path);
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,129 @@
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal abstract class GaugeFrameRenderer
{
#region Private variables
private GaugeFrame _GaugeFrame;
#endregion
protected GaugeFrameRenderer(GaugeFrame gaugeFrame)
{
_GaugeFrame = gaugeFrame;
}
#region Abstract methods
internal abstract void SetBackClipRegion(PaintEventArgs e);
internal abstract void PreRenderContent(PaintEventArgs e);
internal abstract void PostRenderContent(PaintEventArgs e);
protected abstract void RenderFrameByAngle(PaintEventArgs e, Rectangle r);
protected abstract void RenderFrameByCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderFrameByHorizontalCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderFrameByVerticalCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderFrameByNone(PaintEventArgs e, Rectangle r);
protected abstract void RenderBackByAngle(PaintEventArgs e, Rectangle r);
protected abstract void RenderBackByCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderBackByHorizontalCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderBackByVerticalCenter(PaintEventArgs e, Rectangle r);
protected abstract void RenderBackByNone(PaintEventArgs e, Rectangle r);
#endregion
#region Protected properties
protected GaugeFrame GaugeFrame
{
get { return (_GaugeFrame); }
}
#endregion
#region SetFrameRegion
internal virtual void SetFrameRegion()
{
if (GaugeFrame.GaugeControl != null)
GaugeFrame.GaugeControl.Region = null;
}
#endregion
#region RenderFrame
internal void RenderFrame(PaintEventArgs e)
{
int inside = _GaugeFrame.AbsBevelInside;
int outside = _GaugeFrame.AbsBevelOutside;
Rectangle r = _GaugeFrame.Bounds;
r.Inflate(-outside, -outside);
if (r.Width > 0 && r.Height > 0)
{
switch (_GaugeFrame.FrameColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.Angle:
case GradientFillType.StartToEnd:
RenderFrameByAngle(e, r);
break;
case GradientFillType.Center:
RenderFrameByCenter(e, r);
break;
case GradientFillType.HorizontalCenter:
RenderFrameByHorizontalCenter(e, r);
break;
case GradientFillType.VerticalCenter:
RenderFrameByVerticalCenter(e, r);
break;
default:
RenderFrameByNone(e, r);
break;
}
r.Inflate(-inside, -inside);
if (r.Width > 0 && r.Height > 0)
{
switch (_GaugeFrame.BackColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.Angle:
case GradientFillType.StartToEnd:
RenderBackByAngle(e, r);
break;
case GradientFillType.Center:
RenderBackByCenter(e, r);
break;
case GradientFillType.HorizontalCenter:
RenderBackByHorizontalCenter(e, r);
break;
case GradientFillType.VerticalCenter:
RenderBackByVerticalCenter(e, r);
break;
default:
RenderBackByNone(e, r);
break;
}
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,409 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeFrameRoundRectRenderer : GaugeFrameRenderer
{
public GaugeFrameRoundRectRenderer(GaugeFrame gaugeFrame)
: base(gaugeFrame)
{
}
#region SetFrameRegion
internal override void SetFrameRegion()
{
if (GaugeFrame.GaugeControl != null)
{
using (GraphicsPath path = GetRoundRectPath(GaugeFrame.Bounds))
GaugeFrame.GaugeControl.Region = new Region(path);
}
}
#endregion
#region SetBackClipRegion
internal override void SetBackClipRegion(PaintEventArgs e)
{
int inside = GaugeFrame.AbsBevelInside;
int outside = GaugeFrame.AbsBevelOutside;
Rectangle r = GaugeFrame.Bounds;
r.Inflate(-outside - inside, -outside - inside);
if (r.Width > 0 && r.Height > 0)
{
using (GraphicsPath path = GetRoundRectPath(r))
e.Graphics.SetClip(path, CombineMode.Intersect);
}
}
#endregion
#region RenderFrame
#region RenderFrameByAngle
protected override void RenderFrameByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(GaugeFrame.Bounds))
{
using (Brush br = GaugeFrame.FrameColor.GetBrush(GaugeFrame.Bounds))
g.FillPath(br, path);
RenderFrameBorder(g, path);
}
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = GaugeFrame.FrameColor.GetBrush(r, GaugeFrame.FrameColor.GradientAngle + 180))
g.FillPath(br, path);
}
}
#endregion
#region RenderFrameByCenter
protected override void RenderFrameByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(GaugeFrame.Bounds))
{
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.End };
br.SetSigmaBellShape(GaugeFrame.FrameSigmaFocus, GaugeFrame.FrameSigmaScale);
g.FillRectangle(br, GaugeFrame.Bounds);
}
RenderFrameBorder(g, path);
}
using (GraphicsPath path = GetRoundRectPath(r))
{
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = GaugeFrame.Center;
br.CenterColor = GaugeFrame.FrameColor.End;
br.SurroundColors = new Color[] { GaugeFrame.FrameColor.Start };
g.FillRectangle(br, r);
}
}
}
#endregion
#region PaintCircularFrameByHvCenter
protected override void RenderFrameByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 90);
}
protected override void RenderFrameByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderFrameByHvCenter(e, r, 0);
}
private void RenderFrameByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = GaugeFrame.Bounds;
t.Height /= 2;
t.Width /= 2;
using (GraphicsPath path = GetRoundRectPath(GaugeFrame.Bounds))
{
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
RenderFrameBorder(g, path);
}
t = r;
t.Height /= 2;
t.Width /= 2;
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = GaugeFrame.FrameColor.GetBrush(t, angle + 180))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
}
}
#endregion
#region RenderFrameByNone
protected override void RenderFrameByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(GaugeFrame.Bounds))
{
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.Start))
g.FillPath(br, path);
RenderFrameBorder(g, path);
}
if (GaugeFrame.FrameColor.End.IsEmpty == false)
{
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = new SolidBrush(GaugeFrame.FrameColor.End))
g.FillPath(br, path);
}
}
}
#endregion
#region RenderFrameBorder
private void RenderFrameBorder(Graphics g, GraphicsPath path)
{
if (GaugeFrame.FrameColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.FrameColor.BorderColor, GaugeFrame.FrameColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
#endregion
#endregion
#region RenderBack
#region RenderBackByAngle
protected override void RenderBackByAngle(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = GaugeFrame.BackColor.GetBrush(r))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
RenderBackBorder(g, path);
}
}
}
#endregion
#region RenderBackByCenter
protected override void RenderBackByCenter(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(r))
{
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = GaugeFrame.BackColor.Start;
br.SurroundColors = new Color[] { GaugeFrame.BackColor.End };
br.CenterPoint = GaugeFrame.Center;
br.SetSigmaBellShape(GaugeFrame.BackSigmaFocus, GaugeFrame.BackSigmaScale);
g.FillRectangle(br, r);
}
RenderBackBorder(g, path);
}
}
#endregion
#region RenderBackByHvCenter
protected override void RenderBackByHorizontalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 90);
}
protected override void RenderBackByVerticalCenter(PaintEventArgs e, Rectangle r)
{
RenderBackByHvCenter(e, r, 0);
}
private void RenderBackByHvCenter(PaintEventArgs e, Rectangle r, int angle)
{
Graphics g = e.Graphics;
Rectangle t = r;
t.Height /= 2;
t.Width /= 2;
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = GaugeFrame.BackColor.GetBrush(t, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
RenderBackBorder(g, path);
}
}
#endregion
#region RenderBackByNone
protected override void RenderBackByNone(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
using (GraphicsPath path = GetRoundRectPath(r))
{
using (Brush br = new SolidBrush(GaugeFrame.BackColor.Start))
g.FillPath(br, path);
RenderBackBorder(g, path);
}
}
#endregion
#region RenderBackBorder
private void RenderBackBorder(Graphics g, GraphicsPath path)
{
if (GaugeFrame.BackColor.BorderWidth > 0)
{
using (Pen pen = new Pen(
GaugeFrame.BackColor.BorderColor, GaugeFrame.BackColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
#endregion
#endregion
#region GetRoundRectPath
private GraphicsPath GetRoundRectPath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int m = Math.Min(r.Width, r.Height);
int n = (int)(m * GaugeFrame.RoundRectangleArc) + 1;
Rectangle t = new Rectangle(r.Right - n, r.Bottom - n, n, n);
path.AddArc(t, 0, 90);
t.X = r.X;
path.AddArc(t, 90, 90);
t.Y = r.Y;
path.AddArc(t, 180, 90);
t.X = r.Right - n;
path.AddArc(t, 270, 90);
path.CloseAllFigures();
return (path);
}
#endregion
#region PreRenderContent
internal override void PreRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 2.5f, 45);
}
#endregion
#region PostRenderContent
internal override void PostRenderContent(PaintEventArgs e)
{
if (GaugeFrame.AddGlassEffect == true)
AddGlassEffect(e, 2, 90);
}
#endregion
#region AddGlassEffect
private void AddGlassEffect(PaintEventArgs e, float f, float angle)
{
Graphics g = e.Graphics;
Rectangle r = GaugeFrame.BackBounds;
float x = Math.Max(r.Height, r.Width);
using (GraphicsPath path = new GraphicsPath())
{
path.AddLines(new Point[] {
new Point(r.X, r.Y),
new Point(r.X, (int)(r.Y + x / f)),
new Point(r.X + (int)(x / f), r.Y)});
path.CloseFigure();
Color color1 = Color.FromArgb(40, Color.White);
using (LinearGradientBrush br =
new LinearGradientBrush(r, color1, Color.Transparent, angle))
{
g.FillPath(br, path);
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,367 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class DigitalElement : NumericElement
{
#region Private variables
private int _ElemWidth;
private int _ElemHeight;
private int _ElemWidthHalf;
private int _ElemHeightHalf;
private int _SegStep;
private int _SegWidth;
private int _SegWidthHalf;
private bool _NeedRecalcSegments;
private bool _NeedSegments;
private Point[][] _SegPoints;
private int _Segments;
#endregion
public DigitalElement(NumericIndicator numIndicator, int segments, int points)
: base(numIndicator)
{
_SegPoints = new Point[segments][];
for (int i = 0; i < segments; i++)
_SegPoints[i] = new Point[points];
_NeedRecalcSegments = true;
_NeedSegments = true;
}
#region Public properties
#region Value
public override char Value
{
get { return (base.Value); }
set
{
if (base.Value != value)
{
base.Value = value;
_NeedSegments = true;
}
}
}
#endregion
#endregion
#region Internal properties
#region ElemWidth
internal int ElemWidth
{
get { return (_ElemWidth); }
}
#endregion
#region ElemWidthHalf
internal int ElemWidthHalf
{
get { return (_ElemWidthHalf); }
}
#endregion
#region ElemHeight
internal int ElemHeight
{
get { return (_ElemHeight); }
}
#endregion
#region ElemHeightHalf
internal int ElemHeightHalf
{
get { return (_ElemHeightHalf); }
}
#endregion
#region NeedRecalcSegments
internal bool NeedRecalcSegments
{
get { return (_NeedRecalcSegments); }
set { _NeedRecalcSegments = value; }
}
#endregion
#region Segments
internal int Segments
{
get { return (_Segments); }
set
{
if (_Segments != value)
{
_Segments = value;
NumIndicator.Refresh();
}
}
}
#endregion
#region SegPoints
internal Point[][] SegPoints
{
get { return (_SegPoints); }
}
#endregion
#region SegStep
internal int SegStep
{
get { return (_SegStep); }
}
#endregion
#region SegWidth
internal int SegWidth
{
get { return (_SegWidth); }
}
#endregion
#region SegWidthHalf
internal int SegWidthHalf
{
get { return (_SegWidthHalf); }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
if (_NeedRecalcSegments == true)
{
_NeedRecalcSegments = false;
_ElemWidth = 50;
_ElemHeight = 100;
_ElemWidthHalf = _ElemWidth / 2;
_ElemHeightHalf = _ElemHeight / 2;
_SegWidth = (int)(_ElemWidth * NumIndicator.SegmentWidth / 4);
_SegWidth = Math.Max(2, _SegWidth);
_SegWidthHalf = _SegWidth / 2;
_SegStep = _SegWidth / 3;
RecalcSegments();
}
}
if (_NeedSegments == true)
{
_NeedSegments = false;
_Segments = NumIndicator.GaugeControl.
OnGetDigitSegments(NumIndicator, Value, GetDigitSegments(Value));
}
}
#region RecalcSegments
public virtual void RecalcSegments()
{
}
#endregion
#endregion
#region OnGetDigitSegments
public virtual int GetDigitSegments(char value)
{
return (0);
}
#endregion
#region RefreshElements
internal override void RefreshElements()
{
_NeedSegments = true;
NeedRecalcLayout = true;
}
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
if (Bounds.Width > 0 && Bounds.Height > 0)
{
RenderBackground(g, Bounds);
int dx = (int)(Bounds.Width * .2f);
int dy = (int)(Bounds.Height * .2f);
Rectangle r = Bounds;
r.Inflate(-dx, -dy);
Rectangle srcRect = new Rectangle(0, 0, _ElemWidth, _ElemHeight);
GraphicsContainer containerState = g.BeginContainer(r, srcRect, GraphicsUnit.Pixel);
g.SmoothingMode = SmoothingMode.AntiAlias;
g.PixelOffsetMode = PixelOffsetMode.Default;
if (NumIndicator.ShearFactor != 0)
{
Matrix trans = new Matrix();
trans.Shear(NumIndicator.ShearFactor, 0.0F);
g.Transform = trans;
}
Brush brushOn = BrushOn;
Brush brushOff = BrushOff;
RenderSegments(g, brushOn, brushOff);
RenderPoints(g, brushOn, brushOff);
g.EndContainer(containerState);
}
}
#region RenderBackground
private void RenderBackground(Graphics g, Rectangle r)
{
if (NumIndicator.ShearFactor == 0)
{
if (BackColor != null && BackColor.IsEmpty == false)
{
using (Brush br = BackColor.GetBrush(r))
g.FillRectangle(br, r);
}
}
}
#endregion
#region RenderSegments
private void RenderSegments(Graphics g, Brush brushOn, Brush brushOff)
{
for (int i = 0; i < _SegPoints.Length; i++)
{
if ((_Segments & (1 << i)) != 0)
{
if (brushOn != null)
g.FillPolygon(brushOn, _SegPoints[i]);
}
else if (ShowDimSegments == true)
{
if (brushOff != null)
g.FillPolygon(brushOff, _SegPoints[i]);
}
}
}
#endregion
#region RenderPoints
private void RenderPoints(Graphics g, Brush brushOn, Brush brushOff)
{
int dpWidth = (_SegWidth * 3) / 2;
if (ColonPointsOn == true)
RenderColonPoints(g, brushOn, dpWidth);
else if (ShowDimColonPoints == true)
RenderColonPoints(g, brushOff, dpWidth);
if (DecimalPointOn == true)
RenderDecimalPoint(g, brushOn, dpWidth);
else if (ShowDimDecimalPoint == true)
RenderDecimalPoint(g, brushOff, dpWidth);
}
#endregion
#region RenderDecimalPoint
private void RenderDecimalPoint(Graphics g, Brush br, int dpWidth)
{
if (br != null)
{
g.FillEllipse(br, _ElemWidth + _SegWidth,
_ElemHeight - dpWidth, dpWidth, dpWidth);
}
}
#endregion
#region RenderColonPoints
private void RenderColonPoints(Graphics g, Brush br, int dpWidth)
{
if (br != null)
{
g.FillEllipse(br, _ElemWidth + _SegWidth,
_ElemHeightHalf - _SegWidth * 3, dpWidth, dpWidth);
g.FillEllipse(br, _ElemWidth + _SegWidth,
_ElemHeightHalf + _SegWidth * 2, dpWidth, dpWidth);
}
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,847 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class GaugeIndicator : GaugeItem
{
#region Private variables
private bool _AutoSize;
private bool _UnderScale;
private int _RefreshRate;
private double _MinValue;
private double _MaxValue;
private double _Value;
private GradientFillColor _BackColor;
private SizeF _Size;
private PointF _Location;
private Rectangle _Bounds;
private Point _Center;
private Font _Font;
private string _Text;
private string _EmptyString;
private string _OverRangeString;
private string _UnderRangeString;
private bool _Dampening;
private double _DampeningSweepTime;
private double _DValue;
private double _DeltaValue;
private double _DStartValue;
private double _DEndValue;
private long _DStartTicks;
private long _DRefreshTicks;
private GaugeControl _GaugeControl;
#endregion
public GaugeIndicator()
{
_AutoSize = true;
BackColor.BorderColor = Color.Black;
_Size = new SizeF(.07f, .07f);
_Location = new PointF(.5f, .7f);
_UnderScale = true;
_RefreshRate = 10;
_EmptyString = "-";
_OverRangeString = "Error";
_UnderRangeString = "Error";
_MinValue = 0;
_MaxValue = 100;
_Value = double.NaN;
}
#region Public properties
#region AutoSize
/// <summary>
/// Gets or sets whether the indicator contents are auto sized
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(true)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates whether the indicator contents are auto sized.")]
public bool AutoSize
{
get { return (_AutoSize); }
set
{
if (_AutoSize != value)
{
_AutoSize = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region BackColor
/// <summary>
/// Gets or sets the BackColor
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the BackColor.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor BackColor
{
get
{
if (_BackColor == null)
{
_BackColor = new GradientFillColor();
_BackColor.ColorTableChanged += BackColorColorTableChanged;
}
return (_BackColor);
}
set
{
if (_BackColor != null)
_BackColor.ColorTableChanged -= BackColorColorTableChanged;
_BackColor = value;
if (_BackColor != null)
_BackColor.ColorTableChanged += BackColorColorTableChanged;
OnGaugeItemChanged();
}
}
#endregion
#region Bounds
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Rectangle Bounds
{
get { return (_Bounds); }
internal set { _Bounds = value; }
}
#endregion
#region DampeningSweepTime
/// <summary>
/// Gets or sets the time it takes for the indicator to
/// change from its minimum to maximum value, measured in seconds
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(0d)]
[Description("Indicates the time it takes for the indicator to change from its minimum to maximum value, measured in seconds.")]
public double DampeningSweepTime
{
get { return (_DampeningSweepTime); }
set
{
if (_DampeningSweepTime != value)
{
_DampeningSweepTime = value;
OnGaugeItemChanged();
}
}
}
#endregion
#region EmptyString
/// <summary>
/// Gets or sets the text string to display when the Indicator Value is empty (double.NaN)
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue("-")]
[Description("Indicates the text string to display when the Indicator Value is empty (double.NaN).")]
public string EmptyString
{
get { return (_EmptyString); }
set
{
if (_EmptyString != value)
{
_EmptyString = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Font
/// <summary>
/// Gets or sets the text Font
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the text Font.")]
public Font Font
{
get
{
if (_Font == null)
_Font = new Font("Microsoft SanSerif", 12);
return (_Font);
}
set
{
if (_Font != null)
_Font.Dispose();
_Font = value;
AbsFont = null;
OnGaugeItemChanged(true);
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeFont()
{
if (_Font == null)
return (false);
using (Font font = new Font("Microsoft SanSerif", 12))
return (_Font.Equals(font) == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetFont()
{
Font = new Font("Microsoft SanSerif", 12);
}
#endregion
#region GaugeControl
/// <summary>
/// Gets or sets the owning GaugeControl
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GaugeControl GaugeControl
{
get { return (_GaugeControl); }
internal set { _GaugeControl = value; }
}
#endregion
#region Location
/// <summary>
/// Gets or sets the location of the image area, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.LocationEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the location of the image area, specified as a percentage.")]
[TypeConverter(typeof(PointFConverter))]
public PointF Location
{
get { return (_Location); }
set
{
if (_Location != value)
{
_Location = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeLocation()
{
return (_Location.X != .5f || _Location.Y != .7f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetLocation()
{
_Location = new PointF(.5f, .7f);
}
#endregion
#region MaxValue
/// <summary>
/// Gets or sets the Maximum value for the Indicator
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(100d)]
[Description("Indicates the Maximum value for the Indicator.")]
public double MaxValue
{
get { return (_MaxValue); }
set
{
if (_MaxValue != value)
{
_MaxValue = value;
DValue = _Value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region MinValue
/// <summary>
/// Gets or sets the Minimum value for the Indicator
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(0d)]
[Description("Indicates the Minimum value for the Indicator.")]
public double MinValue
{
get { return (_MinValue); }
set
{
if (_MinValue != value)
{
_MinValue = value;
DValue = _Value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region OverRangeString
/// <summary>
/// Gets or sets the text string to display when the Indicator Value is over the set MaxValue range
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue("Error")]
[Description("Indicates the text string to display when the Indicator Value is over the set MaxValue range.")]
public string OverRangeString
{
get { return (_OverRangeString); }
set
{
if (_OverRangeString != value)
{
_OverRangeString = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region RefreshRate
/// <summary>
/// Gets or sets how often the indicator is refreshed per second
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(10)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates how often the indicator is refreshed per second.")]
public int RefreshRate
{
get { return (_RefreshRate); }
set
{
if (_RefreshRate != value)
{
if (value <= 0 || value > 1000)
throw new ArgumentException("Value must be between 1 and 100");
_RefreshRate = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Size
/// <summary>
/// Gets or sets the size of the indicator, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.SizeEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the size of the indicator, specified as a percentage.")]
public SizeF Size
{
get { return (_Size); }
set
{
if (_Size != value)
{
_Size = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSize()
{
return (_Size.Width != .07f || _Size.Height != .07f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSize()
{
_Size = new SizeF(.07f, .07f);
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text to be displayed
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(null)]
[Description("Indicates the text to be displayed.")]
public string Text
{
get { return (_Text); }
set
{
if (_Text != value)
{
_Text = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region UnderRangeString
/// <summary>
/// Gets or sets the text string to display when the Indicator Value is under the set MinValue range
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue("Error")]
[Description("Indicates the text string to display when the Indicator Value is under the set MinValue range.")]
public string UnderRangeString
{
get { return (_UnderRangeString); }
set
{
if (_UnderRangeString != value)
{
_UnderRangeString = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region UnderScale
/// <summary>
/// Gets or sets whether the indicator is displayed under the scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(true)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates whether the indicator is displayed under the scale.")]
public bool UnderScale
{
get { return (_UnderScale); }
set
{
if (_UnderScale != value)
{
_UnderScale = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Value
/// <summary>
/// Gets or sets the indicator value
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(double.NaN)]
[Description("Indicates the indicator value.")]
public double Value
{
get { return (_Value); }
set
{
if (_Value != value)
{
_Value = value;
OnValueChanged(true);
}
}
}
#endregion
#region ValueEx
/// <summary>
/// Gets or sets the value of the indicator - but with no dampening
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public double ValueEx
{
get { return (_Value); }
set
{
if (_Value != value)
{
_Value = value;
OnValueChanged(false);
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsFont
// ReSharper disable ValueParameterNotUsed
internal virtual Font AbsFont
{
get { return (Font); }
set { }
}
// ReSharper restore ValueParameterNotUsed
#endregion
#region Center
internal Point Center
{
get { return (_Center); }
}
#endregion
#region DValue
internal double DValue
{
get { return (_DValue); }
set
{
_DValue = value;
if (GaugeControl != null)
GaugeControl.DValueChange = true;
OnGaugeItemChanged(true);
}
}
#endregion
#endregion
#region Event processing
#region BackColor processing
void BackColorColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#endregion
#region OnValueChanged
internal virtual void OnValueChanged(bool dampen)
{
if (GaugeControl != null && Visible == true)
{
if (GaugeControl.InDesignMode == false)
{
if (_DValue < _Value)
{
double start = Math.Max(_MinValue, _DValue);
if (start < _MaxValue)
{
if (StartDampening(dampen, start, Math.Min(_MaxValue, _Value)))
return;
}
}
else if (_DValue > _Value)
{
double start = Math.Min(_MaxValue, _DValue);
if (start > _MinValue)
{
if (StartDampening(dampen, start, Math.Max(_MinValue, _Value)))
return;
}
}
}
}
DValue = _Value;
}
#endregion
#region Dampening support
#region StartDampening
private bool StartDampening(bool dampen, double start, double end)
{
double dampenTime = _DampeningSweepTime;
if (GaugeControl.IsHandleCreated &&
dampen == true && dampenTime > 0)
{
_DStartValue = start;
_DEndValue = end;
_DeltaValue = (_MaxValue - _MinValue) / (dampenTime * 1000);
_DStartTicks = DateTime.Now.Ticks;
if (_Dampening == false)
{
_Dampening = true;
_DRefreshTicks = _DStartTicks;
_GaugeControl.DampeningUpdate += DampeningUpdate;
_GaugeControl.StartDampening();
}
return (true);
}
return (false);
}
#endregion
#region DampeningUpdate
void DampeningUpdate(object sender, EventArgs e)
{
SetIndicatorValue();
if (_DValue == _DEndValue)
{
if (_Dampening == true)
{
_GaugeControl.DampeningUpdate -= DampeningUpdate;
_GaugeControl.StopDampening();
_Dampening = false;
}
}
}
#endregion
#region SetIndicatorValue
private void SetIndicatorValue()
{
long now = DateTime.Now.Ticks;
double ms = new TimeSpan(now - _DStartTicks).TotalMilliseconds;
double delta = _DeltaValue * ms;
if (delta > 0)
{
double n = (_DValue <= _Value)
? Math.Min(_DStartValue + delta, _DEndValue)
: Math.Max(_DStartValue - delta, _DEndValue);
if (n == _DEndValue ||
new TimeSpan(now - _DRefreshTicks).TotalMilliseconds > 1000 / _RefreshRate)
{
_DRefreshTicks = now;
DValue = n;
}
}
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
bool autoCenter = _GaugeControl.Frame.AutoCenter;
_Center = _GaugeControl.GetAbsPoint(_Location, autoCenter);
Size size = _GaugeControl.GetAbsSize(_Size, autoCenter);
_Bounds = new Rectangle(
_Center.X - size.Width / 2, _Center.Y - size.Height / 2,
size.Width, size.Height);
}
#endregion
#region Contains
internal virtual bool Contains(Point pt)
{
return (Bounds.Contains(pt));
}
#endregion
#region GetOverrideString
protected string GetOverrideString()
{
string s = null;
if (String.IsNullOrEmpty(Text) == false)
s = Text;
else if (Value.Equals(double.NaN) == true)
s = _EmptyString ?? "";
else if (Value < MinValue)
s = _UnderRangeString;
else if (Value > MaxValue)
s = _OverRangeString ?? "";
return (s);
}
#endregion
#region ProcessTemplateText
protected override void ProcessTemplateText(
GaugeControl gauge, StringBuilder sb, string key, string data)
{
if (key.Equals("Value") == true)
{
sb.Append(string.IsNullOrEmpty(data)
? _Value.ToString()
: String.Format("{0:" + data + "}", _Value));
}
else
{
base.ProcessTemplateText(gauge, sb, key, data);
}
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeIndicator c = copy as GaugeIndicator;
if (c != null)
{
base.CopyToItem(c);
c.AutoSize = _AutoSize;
if (_BackColor != null)
c.BackColor = (GradientFillColor)_BackColor.Clone();
c.DampeningSweepTime = _DampeningSweepTime;
c.EmptyString = _EmptyString;
if (_Font != null)
c.Font = (Font)_Font.Clone();
c.Location = _Location;
c.MaxValue = _MaxValue;
c.MinValue = _MinValue;
c.OverRangeString = _OverRangeString;
c.RefreshRate = _RefreshRate;
c.Size = _Size;
c.Text = _Text;
c.UnderRangeString = _UnderRangeString;
c.UnderScale = _UnderScale;
c.Value = _Value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,231 @@
using System;
using System.ComponentModel;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class IndicatorRangeCollection : GenericCollection<IndicatorRange>
{
#region ICloneable Members
public override object Clone()
{
IndicatorRangeCollection copy = new IndicatorRangeCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(IndicatorRangeCollection copy)
{
foreach (IndicatorRange item in this)
{
IndicatorRange ic = new IndicatorRange();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
public class IndicatorRange : GaugeItem
{
#region Events
[Description("Occurs when the IndicatorRange changes.")]
public event EventHandler<EventArgs> IndicatorRangeChanged;
#endregion
#region Private variables
private double _StartValue;
private double _EndValue;
private GradientFillColor _BackColor;
#endregion
#region Hidden properties
#region Tooltip
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new string Tooltip
{
get { return (base.Tooltip); }
set { base.Tooltip = value; }
}
#endregion
#region Visible
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool Visible
{
get { return (base.Visible); }
set { base.Visible = value; }
}
#endregion
#endregion
#region Public properties
#region BackColor
/// <summary>
/// Gets or sets the BackColor
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the BackColor.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor BackColor
{
get
{
if (_BackColor == null)
{
_BackColor = new GradientFillColor();
_BackColor.ColorTableChanged += BackColor_ColorTableChanged;
}
return (_BackColor);
}
set
{
if (_BackColor != null)
_BackColor.ColorTableChanged -= BackColor_ColorTableChanged;
_BackColor = value;
if (_BackColor != null)
_BackColor.ColorTableChanged += BackColor_ColorTableChanged;
OnIndicatorRangeChanged();
}
}
#endregion
#region EndValue
/// <summary>
/// Gets or sets the Ending range value
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(double.NaN)]
[Description("Indicates the Ending range value.")]
public double EndValue
{
get { return (_EndValue); }
set
{
if (_EndValue != value)
{
_EndValue = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region StartValue
/// <summary>
/// Gets or sets the Starting range value
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(double.NaN)]
[Description("Indicates the Starting range value.")]
public double StartValue
{
get { return (_StartValue); }
set
{
if (_StartValue != value)
{
_StartValue = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#endregion
#region Event processing
#region BackColor processing
void BackColor_ColorTableChanged(object sender, EventArgs e)
{
OnIndicatorRangeChanged();
}
#endregion
#region OnIndicatorRangeChanged
internal void OnIndicatorRangeChanged()
{
if (IndicatorRangeChanged != null)
IndicatorRangeChanged(this, EventArgs.Empty);
}
#endregion
#endregion
#region ICloneable Members
public override object Clone()
{
IndicatorRange copy = new IndicatorRange();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
IndicatorRange c = copy as IndicatorRange;
if (c != null)
{
base.CopyToItem(c);
c.EndValue = _EndValue;
c.StartValue = _StartValue;
if (_BackColor != null)
c.BackColor = (GradientFillColor) _BackColor.Clone();
}
}
#endregion
}
}

View File

@@ -0,0 +1,69 @@
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class MechanicalElement : NumericElement
{
#region Private variables
private int _Descent;
#endregion
public MechanicalElement(NumericIndicator numIndicator)
: base(numIndicator)
{
}
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
Font font = NumIndicator.AbsFont;
FontFamily family = new FontFamily(font.Name);
int descent = family.GetCellDescent(font.Style);
float descentPixel = font.Size * descent / family.GetEmHeight(font.Style);
_Descent = (int)(descentPixel / 2) + 1;
}
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (Bounds.Width > 0 && Bounds.Height > 0)
{
Graphics g = e.Graphics;
if (BackColor != null && BackColor.IsEmpty == false)
{
Rectangle r = GetPaddedRect(Bounds);
using (Brush br = BackColor.GetBrush(r))
g.FillRectangle(br, r);
}
using (StringFormat sf = new StringFormat())
{
sf.Alignment = StringAlignment.Center;
sf.LineAlignment = StringAlignment.Center;
Rectangle r = Bounds;
r.Y += _Descent;
g.DrawString(Value.ToString(), NumIndicator.AbsFont, BrushOn, r, sf);
}
}
}
#endregion
}
}

View File

@@ -0,0 +1,441 @@
using System;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class NumericElement : IDisposable
{
#region Private variables
private Rectangle _Bounds;
private NumericIndicator _NumIndicator;
private char _Value;
private bool _ColonPointsOn;
private bool _DecimalPointOn;
private bool _ShowDimColonPoints;
private bool _ShowDimDecimalPoint;
private bool _ShowDimSegments;
private Color _DigitColor;
private Color _DigitDimColor;
private GradientFillColor _BackColor;
private Brush _BrushOn;
private Brush _BrushOff;
private bool _NeedRecalcLayout;
private bool _InRender;
#endregion
public NumericElement(NumericIndicator numIndicator)
{
_NumIndicator = numIndicator;
_ShowDimColonPoints = true;
_ShowDimDecimalPoint = true;
_ShowDimSegments = true;
}
#region Public properties
#region BackColor
public GradientFillColor BackColor
{
get { return (_BackColor); }
set
{
_BackColor = value;
Refresh();
}
}
#endregion
#region Bounds
public Rectangle Bounds
{
get { return (_Bounds); }
internal set
{
if (_Bounds.Equals(value) == false)
{
_Bounds = value;
_NeedRecalcLayout = true;
}
}
}
#endregion
#region ColonPointsOn
public bool ColonPointsOn
{
get { return (_ColonPointsOn); }
set
{
if (_ColonPointsOn != value)
{
_ColonPointsOn = value;
Refresh();
}
}
}
#endregion
#region DecimalPointOn
public bool DecimalPointOn
{
get { return (_DecimalPointOn); }
set
{
if (_DecimalPointOn != value)
{
_DecimalPointOn = value;
Refresh();
}
}
}
#endregion
#region DigitColor
/// <summary>
/// Gets or sets the Digit Color
/// </summary>
public Color DigitColor
{
get { return (_DigitColor); }
set
{
if (_DigitColor != value)
{
BrushOn = null;
_DigitColor = value;
Refresh();
}
}
}
#endregion
#region DigitDimColor
/// <summary>
/// Gets or sets the default Digit Dim Color (Dim LED color)
/// </summary>
public Color DigitDimColor
{
get { return (_DigitDimColor); }
set
{
if (_DigitDimColor != value)
{
BrushOff = null;
_DigitDimColor = value;
Refresh();
}
}
}
#endregion
#region ShowDimColonPoints
public bool ShowDimColonPoints
{
get { return (_ShowDimColonPoints); }
set
{
if (_ShowDimColonPoints != value)
{
_ShowDimColonPoints = value;
Refresh();
}
}
}
#endregion
#region ShowDimDecimalPoint
public bool ShowDimDecimalPoint
{
get { return (_ShowDimDecimalPoint); }
set
{
if (_ShowDimDecimalPoint != value)
{
_ShowDimDecimalPoint = value;
Refresh();
}
}
}
#endregion
#region ShowDimSegments
/// <summary>
/// Gets or sets the whether dim segments are displayed
/// </summary>
public bool ShowDimSegments
{
get { return (_ShowDimSegments); }
set
{
if (_ShowDimSegments != value)
{
BrushOff = null;
_ShowDimSegments = value;
Refresh();
}
}
}
#endregion
#region Value
public virtual char Value
{
get { return (_Value); }
set
{
if (_Value != value)
{
_Value = value;
Refresh();
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsSegmentWidth
internal int AbsSegmentWidth
{
get { return ((int)(Bounds.Width * _NumIndicator.SegmentWidth)); }
}
#endregion
#region BrushOn
internal Brush BrushOn
{
get
{
if (_BrushOn == null)
{
if (_DigitColor.IsEmpty == false)
_BrushOn = new SolidBrush(_DigitColor);
}
return (_BrushOn);
}
set
{
if (_BrushOn != null)
_BrushOn.Dispose();
_BrushOn = value;
}
}
#endregion
#region BrushOff
internal Brush BrushOff
{
get
{
if (_BrushOff == null)
{
if (DigitDimColor.IsEmpty == false)
_BrushOff = new SolidBrush(_DigitDimColor);
}
return (_BrushOff);
}
set
{
if (_BrushOff != null)
_BrushOff.Dispose();
_BrushOff = value;
}
}
#endregion
#region CanRefresh
internal bool CanRefresh
{
get { return (_InRender == false); }
}
#endregion
#region InPaint
internal bool InRenderCallout
{
get { return (_InRender); }
set { _InRender = value; }
}
#endregion
#region NeedRecalcLayout
internal bool NeedRecalcLayout
{
get { return (_NeedRecalcLayout); }
set { _NeedRecalcLayout = value; }
}
#endregion
#region NumIndicator
/// <summary>
/// Gets or sets the owning NumericIndicator
/// </summary>
internal NumericIndicator NumIndicator
{
get { return (_NumIndicator); }
set { _NumIndicator = value; }
}
#endregion
#endregion
#region RecalcLayout
public virtual void RecalcLayout()
{
if (_NeedRecalcLayout == true)
_NeedRecalcLayout = false;
}
#endregion
#region OnPaint
public virtual void OnPaint(PaintEventArgs e)
{
RecalcLayout();
}
#endregion
#region Refresh
internal void Refresh()
{
if (CanRefresh == true)
NumIndicator.Refresh();
}
#endregion
#region RefreshElements
internal virtual void RefreshElements()
{
}
#endregion
#region GetPaddedRect
internal Rectangle GetPaddedRect(Rectangle r)
{
Padding padding = _NumIndicator.Padding;
r.Y -= padding.Top;
r.Height += (padding.Top + padding.Bottom);
if (_NumIndicator.Digits[0] == this)
{
r.X -= padding.Left;
r.Width += padding.Left;
}
if (_NumIndicator.Digits[_NumIndicator.Digits.Length - 1] == this)
r.Width += padding.Right;
return (r);
}
#endregion
#region IDisposable Members
public virtual void Dispose()
{
BrushOn = null;
BrushOff = null;
}
#endregion
#region CopyToItem
public virtual void CopyToItem(NumericElement copy)
{
copy.BackColor = _BackColor;
copy.Bounds = _Bounds;
copy.DigitDimColor = _DigitDimColor;
copy.ColonPointsOn = _ColonPointsOn;
copy.DigitColor = _DigitColor;
copy.DigitDimColor = _DigitDimColor;
copy.ShowDimColonPoints = _ShowDimColonPoints;
copy.ShowDimDecimalPoint = _ShowDimDecimalPoint;
copy.ShowDimSegments = _ShowDimSegments;
copy.Value = _Value;
}
#endregion
}
}

View File

@@ -0,0 +1,215 @@
using System.ComponentModel;
using System.Drawing;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class NumericRangeCollection : GenericCollection<NumericRange>
{
#region GetValueRange
public NumericRange GetValueRange(double value)
{
foreach (NumericRange range in this)
{
if (value >= range.StartValue && value <= range.EndValue)
return (range);
}
return (null);
}
#endregion
#region ICloneable Members
public override object Clone()
{
NumericRangeCollection copy = new NumericRangeCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(NumericRangeCollection copy)
{
foreach (NumericRange item in this)
{
NumericRange ic = new NumericRange();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
public class NumericRange : IndicatorRange
{
#region Private variables
private Color _DigitColor;
private Color _DigitDimColor;
private Color _DecimalColor;
private Color _DecimalDimColor;
private NumericIndicator _NumericIndicator;
#endregion
#region Public properties
#region DecimalColor
/// <summary>
/// Gets or sets the default Decimal Color
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "FireBrick")]
[Description("Indicates the default Decimal Color.")]
public Color DecimalColor
{
get { return (_DecimalColor); }
set
{
if (_DecimalColor != value)
{
_DecimalColor = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region DecimalDimColor
/// <summary>
/// Gets or sets the default Decimal Dim Color (Dim LED color)
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Empty")]
[Description("Indicates the default Decimal Dim Color (Dim LED color).")]
public Color DecimalDimColor
{
get { return (_DecimalDimColor); }
set
{
if (_DecimalDimColor != value)
{
_DecimalDimColor = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region DigitColor
/// <summary>
/// Gets or sets the default Digit Color
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "SteelBlue")]
[Description("Indicates the default Digit Color.")]
public Color DigitColor
{
get { return (_DigitColor); }
set
{
if (_DigitColor != value)
{
_DigitColor = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region DigitDimColor
/// <summary>
/// Gets or sets the default Digit Dim Color (Dim LED color)
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Empty")]
[Description("Indicates the default Digit Dim Color (Dim LED color).")]
public Color DigitDimColor
{
get { return (_DigitDimColor); }
set
{
if (_DigitDimColor != value)
{
_DigitDimColor = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region NumericIndicator
/// <summary>
/// Gets or sets the NumericIndicator
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public NumericIndicator NumericIndicator
{
get { return (_NumericIndicator); }
internal set { _NumericIndicator = value; }
}
#endregion
#endregion
#region ICloneable Members
public override object Clone()
{
NumericRange copy = new NumericRange();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
NumericRange c = copy as NumericRange;
if (c != null)
{
base.CopyToItem(c);
c.DecimalColor = _DecimalColor;
c.DecimalDimColor = _DecimalDimColor;
c.DigitColor = _DigitColor;
c.DigitDimColor = _DigitDimColor;
}
}
#endregion
}
}

View File

@@ -0,0 +1,572 @@
using System;
using System.Drawing;
namespace DevComponents.Instrumentation
{
public class Seg16Element : DigitalElement
{
#region Private variables
private int _DiagSlant;
private int _DiagWidth;
#endregion
public Seg16Element(NumericIndicator numIndicator)
: base(numIndicator, 16, 6)
{
}
#region RecalcSegments
public override void RecalcSegments()
{
double d = (ElemWidth * NumIndicator.SegmentWidth) / 8;
_DiagWidth = (int)(Math.Sqrt((d * d) * 2));
_DiagWidth = Math.Max(1, _DiagWidth);
d = Math.Sqrt(ElemHeight * ElemHeight + ElemWidth * ElemWidth) / 2;
_DiagSlant = (int)((SegWidth * d) / ElemWidthHalf);
CalcSegment0();
CalcSegment1();
CalcSegment2();
CalcSegment3();
CalcSegment4();
CalcSegment5();
CalcSegment6();
CalcSegment7();
CalcSegment8();
CalcSegment9();
CalcSegment10();
CalcSegment11();
CalcSegment12();
CalcSegment13();
CalcSegment14();
CalcSegment15();
}
#region CalcSegment0
private void CalcSegment0()
{
Point[] pts = SegPoints[0];
pts[0].X = SegWidth + 1; pts[0].Y = 0;
pts[1].X = ElemWidthHalf - 1; pts[1].Y = 0;
pts[2].X = ElemWidthHalf - 1; pts[2].Y = SegStep;
pts[3].X = ElemWidthHalf - SegWidthHalf - 1; pts[3].Y = SegWidth;
pts[4].X = SegWidth + 1; pts[4].Y = SegWidth;
pts[5].X = SegWidthHalf + 1; pts[5].Y = SegWidthHalf;
}
#endregion
#region CalcSegment1
private void CalcSegment1()
{
Point[] pts = SegPoints[1];
pts[0].X = ElemWidthHalf + 1; pts[0].Y = 0;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = 0;
pts[2].X = ElemWidth - SegWidthHalf - 1; pts[2].Y = SegWidthHalf;
pts[3].X = ElemWidth - SegWidth - 1; pts[3].Y = SegWidth;
pts[4].X = ElemWidthHalf + SegWidthHalf + 1; pts[4].Y = SegWidth;
pts[5].X = ElemWidthHalf + 1; pts[5].Y = SegStep;
}
#endregion
#region CalcSegment2
private void CalcSegment2()
{
Point[] pts = SegPoints[2];
pts[0].X = 0; pts[0].Y = SegWidth + 1;
pts[1].X = SegWidthHalf; pts[1].Y = SegWidthHalf + 1;
pts[2].X = SegWidth; pts[2].Y = pts[0].Y;
pts[3].X = pts[2].X; pts[3].Y = ElemHeightHalf - SegWidthHalf - 1;
pts[4].X = SegStep; pts[4].Y = ElemHeightHalf - 1;
pts[5].X = 0; pts[5].Y = pts[4].Y;
}
#endregion
#region CalcSegment3
private void CalcSegment3()
{
Point[] pts = SegPoints[3];
pts[0].X = SegWidth + 1; pts[0].Y = pts[0].X;
pts[1].X = pts[0].X + _DiagWidth; pts[1].Y = pts[0].Y;
pts[2].X = ElemWidthHalf - SegWidthHalf - 1; pts[2].Y = ElemHeightHalf - SegWidthHalf - _DiagSlant;
pts[3].X = pts[2].X; pts[3].Y = pts[2].Y + _DiagSlant;
pts[4].X = pts[0].X; pts[4].Y = pts[0].Y + _DiagWidth;
pts[5].X = pts[0].X; pts[5].Y = pts[0].Y;
}
#endregion
#region CalcSegment4
private void CalcSegment4()
{
Point[] pts = SegPoints[4];
pts[0].X = ElemWidthHalf - SegWidthHalf; pts[0].Y = SegWidth + 1;
pts[1].X = ElemWidthHalf; pts[1].Y = SegStep + 1;
pts[2].X = ElemWidthHalf + SegWidthHalf; pts[2].Y = pts[0].Y;
pts[3].X = pts[2].X; pts[3].Y = ElemHeightHalf - SegWidthHalf - 1;
pts[4].X = pts[1].X; pts[4].Y = ElemHeightHalf - 1;
pts[5].X = pts[0].X; pts[5].Y = pts[3].Y;
}
#endregion
#region CalcSegment5
private void CalcSegment5()
{
Point[] pts = SegPoints[5];
pts[0].X = ElemWidth - SegWidth - _DiagWidth - 1; pts[0].Y = SegWidth + 1;
pts[1].X = pts[0].X + _DiagWidth; pts[1].Y = pts[0].Y;
pts[2].X = pts[1].X; pts[2].Y = pts[1].Y + _DiagWidth;
pts[3].X = ElemWidthHalf + SegWidthHalf + 1; pts[3].Y = ElemHeightHalf - SegWidthHalf;
pts[4].X = pts[3].X; pts[4].Y = pts[3].Y - _DiagSlant;
pts[5].X = pts[0].X; pts[5].Y = pts[0].Y;
}
#endregion
#region CalcSegment6
private void CalcSegment6()
{
Point[] pts = SegPoints[6];
pts[0].X = ElemWidth - SegWidth; pts[0].Y = SegWidth + 1;
pts[1].X = pts[0].X + SegWidthHalf; pts[1].Y = SegWidthHalf + 1;
pts[2].X = ElemWidth; pts[2].Y = pts[0].Y;
pts[3].X = pts[2].X; pts[3].Y = ElemHeightHalf - 1;
pts[4].X = pts[3].X - SegStep; pts[4].Y = pts[3].Y;
pts[5].X = ElemWidth - SegWidth; pts[5].Y = pts[3].Y - SegWidthHalf;
}
#endregion
#region CalcSegment7
private void CalcSegment7()
{
Point[] pts = SegPoints[7];
pts[0].X = SegWidth + 1; pts[0].Y = ElemHeightHalf - SegWidthHalf;
pts[1].X = ElemWidthHalf - SegWidthHalf - 1; pts[1].Y = pts[0].Y;
pts[2].X = ElemWidthHalf - 1; pts[2].Y = ElemHeightHalf;
pts[3].X = pts[1].X; pts[3].Y = ElemHeightHalf + SegWidthHalf;
pts[4].X = pts[0].X; pts[4].Y = pts[3].Y;
pts[5].X = SegStep + 1; pts[5].Y = pts[2].Y;
}
#endregion
#region CalcSegment8
private void CalcSegment8()
{
Point[] pts = SegPoints[8];
pts[0].X = ElemWidthHalf + SegWidthHalf + 1; pts[0].Y = ElemHeightHalf - SegWidthHalf;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = pts[0].Y;
pts[2].X = ElemWidth - SegStep - 1; pts[2].Y = ElemHeightHalf;
pts[3].X = pts[1].X; pts[3].Y = ElemHeightHalf + SegWidthHalf;
pts[4].X = pts[0].X; pts[4].Y = pts[3].Y;
pts[5].X = ElemWidthHalf + 1; pts[5].Y = pts[2].Y;
}
#endregion
#region CalcSegment9
private void CalcSegment9()
{
Point[] pts = SegPoints[9];
pts[0].X = 0; pts[0].Y = ElemHeightHalf + 1;
pts[1].X = SegStep; pts[1].Y = pts[0].Y;
pts[2].X = SegWidth; pts[2].Y = pts[1].Y + SegWidthHalf;
pts[3].X = pts[2].X; pts[3].Y = ElemHeight - SegWidth - 1;
pts[4].X = SegWidthHalf; pts[4].Y = ElemHeight - SegWidthHalf - 1;
pts[5].X = 0; pts[5].Y = pts[3].Y;
}
#endregion
#region CalcSegment10
private void CalcSegment10()
{
Point[] pts = SegPoints[10];
pts[0].X = ElemWidthHalf - SegWidthHalf - 1; pts[0].Y = ElemHeightHalf + SegWidthHalf;
pts[1].X = pts[0].X; pts[1].Y = pts[0].Y + _DiagSlant;
pts[2].X = SegWidth + _DiagWidth + 1; pts[2].Y = ElemHeight - SegWidth - 1;
pts[3].X = SegWidth + 1; pts[3].Y = ElemHeight - SegWidth - 1;
pts[4].X = pts[3].X; pts[4].Y = pts[3].Y - _DiagWidth;
pts[5].X = pts[0].X; pts[5].Y = pts[0].Y;
}
#endregion
#region CalcSegment11
private void CalcSegment11()
{
Point[] pts = SegPoints[11];
pts[0].X = ElemWidthHalf - SegWidthHalf; pts[0].Y = ElemHeightHalf + SegWidthHalf + 1;
pts[1].X = ElemWidthHalf; pts[1].Y = ElemHeightHalf + 1;
pts[2].X = ElemWidthHalf + SegWidthHalf; pts[2].Y = pts[0].Y;
pts[3].X = pts[2].X; pts[3].Y = ElemHeight - SegWidth - 1;
pts[4].X = pts[1].X; pts[4].Y = ElemHeight - SegStep - 1;
pts[5].X = pts[0].X; pts[5].Y = pts[3].Y;
}
#endregion
#region CalcSegment12
private void CalcSegment12()
{
Point[] pts = SegPoints[12];
pts[0].X = ElemWidthHalf + SegWidthHalf + 1; pts[0].Y = ElemHeightHalf + SegWidthHalf;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = ElemHeight - SegWidth - _DiagWidth - 1;
pts[2].X = pts[1].X; pts[2].Y = pts[1].Y + _DiagWidth;
pts[3].X = pts[2].X - _DiagWidth; pts[3].Y = pts[2].Y;
pts[4].X = pts[0].X; pts[4].Y = pts[0].Y + _DiagSlant;
pts[5].X = pts[0].X; pts[5].Y = pts[0].Y;
}
#endregion
#region CalcSegment13
private void CalcSegment13()
{
Point[] pts = SegPoints[13];
pts[0].X = ElemWidth - SegStep; pts[0].Y = ElemHeightHalf + 1;
pts[1].X = ElemWidth; pts[1].Y = pts[0].Y;
pts[2].X = pts[1].X; pts[2].Y = ElemHeight - SegWidth - 1;
pts[3].X = ElemWidth - SegWidthHalf; pts[3].Y = ElemHeight - SegWidthHalf - 1;
pts[4].X = ElemWidth - SegWidth; pts[4].Y = pts[2].Y;
pts[5].X = pts[4].X; pts[5].Y = ElemHeightHalf + SegWidthHalf + 1;
}
#endregion
#region CalcSegment14
private void CalcSegment14()
{
Point[] pts = SegPoints[14];
pts[0].X = SegWidth + 1; pts[0].Y = ElemHeight - SegWidth;
pts[1].X = ElemWidthHalf - SegWidthHalf - 1; pts[1].Y = pts[0].Y;
pts[2].X = ElemWidthHalf - 1; pts[2].Y = ElemHeight - SegStep;
pts[3].X = pts[2].X; pts[3].Y = ElemHeight;
pts[4].X = pts[0].X; pts[4].Y = pts[3].Y;
pts[5].X = SegWidthHalf + 1; pts[5].Y = ElemHeight - SegWidthHalf;
}
#endregion
#region CalcSegment15
private void CalcSegment15()
{
Point[] pts = SegPoints[15];
pts[0].X = ElemWidthHalf + SegWidthHalf + 1; pts[0].Y = ElemHeight - SegWidth;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = pts[0].Y;
pts[2].X = ElemWidth - SegWidthHalf - 1; pts[2].Y = ElemHeight - SegWidthHalf;
pts[3].X = pts[1].X; pts[3].Y = ElemHeight;
pts[4].X = ElemWidthHalf + 1; pts[4].Y = ElemHeight;
pts[5].X = pts[4].X; pts[5].Y = ElemHeight - SegStep;
}
#endregion
#endregion
#region GetDigitSegments
public override int GetDigitSegments(char digit)
{
switch (digit)
{
#region Numeric
case '0': return ((int)Seg16Segments.Zero);
case '1': return ((int)Seg16Segments.One);
case '2': return ((int)Seg16Segments.Two);
case '3': return ((int)Seg16Segments.Three);
case '4': return ((int)Seg16Segments.Four);
case '5': return ((int)Seg16Segments.Five);
case '6': return ((int)Seg16Segments.Six);
case '7': return ((int)Seg16Segments.Seven);
case '8': return ((int)Seg16Segments.Eight);
case '9': return ((int)Seg16Segments.Nine);
#endregion
#region Lowercase Alpha
case 'a': return ((int)Seg16Segments.a);
case 'b': return ((int)Seg16Segments.b);
case 'c': return ((int)Seg16Segments.c);
case 'd': return ((int)Seg16Segments.d);
case 'e': return ((int)Seg16Segments.e);
case 'f': return ((int)Seg16Segments.f);
case 'g': return ((int)Seg16Segments.g);
case 'h': return ((int)Seg16Segments.h);
case 'i': return ((int)Seg16Segments.i);
case 'j': return ((int)Seg16Segments.j);
case 'k': return ((int)Seg16Segments.k);
case 'l': return ((int)Seg16Segments.l);
case 'm': return ((int)Seg16Segments.m);
case 'n': return ((int)Seg16Segments.n);
case 'o': return ((int)Seg16Segments.o);
case 'p': return ((int)Seg16Segments.p);
case 'q': return ((int)Seg16Segments.q);
case 'r': return ((int)Seg16Segments.r);
case 's': return ((int)Seg16Segments.s);
case 't': return ((int)Seg16Segments.t);
case 'u': return ((int)Seg16Segments.u);
case 'v': return ((int)Seg16Segments.v);
case 'w': return ((int)Seg16Segments.w);
case 'x': return ((int)Seg16Segments.x);
case 'y': return ((int)Seg16Segments.y);
case 'z': return ((int)Seg16Segments.z);
#endregion
#region Uppercase alpha
case 'A': return ((int)Seg16Segments.A);
case 'B': return ((int)Seg16Segments.B);
case 'C': return ((int)Seg16Segments.C);
case 'D': return ((int)Seg16Segments.D);
case 'E': return ((int)Seg16Segments.E);
case 'F': return ((int)Seg16Segments.F);
case 'G': return ((int)Seg16Segments.G);
case 'H': return ((int)Seg16Segments.H);
case 'I': return ((int)Seg16Segments.I);
case 'J': return ((int)Seg16Segments.J);
case 'K': return ((int)Seg16Segments.K);
case 'L': return ((int)Seg16Segments.L);
case 'M': return ((int)Seg16Segments.M);
case 'N': return ((int)Seg16Segments.N);
case 'O': return ((int)Seg16Segments.O);
case 'P': return ((int)Seg16Segments.P);
case 'Q': return ((int)Seg16Segments.Q);
case 'R': return ((int)Seg16Segments.R);
case 'S': return ((int)Seg16Segments.S);
case 'T': return ((int)Seg16Segments.T);
case 'U': return ((int)Seg16Segments.U);
case 'V': return ((int)Seg16Segments.V);
case 'W': return ((int)Seg16Segments.W);
case 'X': return ((int)Seg16Segments.X);
case 'Y': return ((int)Seg16Segments.Y);
case 'Z': return ((int)Seg16Segments.Z);
#endregion
#region Extended chars
case ' ': return ((int)Seg16Segments.Space);
case '!': return ((int)Seg16Segments.ExPoint);
case '"': return ((int)Seg16Segments.DQuote);
case '#': return ((int)Seg16Segments.PoundSign);
case '$': return ((int)Seg16Segments.DollarSign);
case '%': return ((int)Seg16Segments.PercentSign);
case '&': return ((int)Seg16Segments.Ampersand);
case '\'': return ((int)Seg16Segments.SQuote);
case '(': return ((int)Seg16Segments.LParen);
case ')': return ((int)Seg16Segments.RParen);
case '*': return ((int)Seg16Segments.Asterisk);
case '+': return ((int)Seg16Segments.PlusSign);
case ',': return ((int)Seg16Segments.Comma);
case '-': return ((int)Seg16Segments.Dash);
case '/': return ((int)Seg16Segments.FSlash);
case ':': return ((int)Seg16Segments.Colon);
case ';': return ((int)Seg16Segments.Semicolon);
case '<': return ((int)Seg16Segments.LessThan);
case '=': return ((int)Seg16Segments.Equals);
case '>': return ((int)Seg16Segments.GreaterThan);
case '?': return ((int)Seg16Segments.QuestionMark);
case '@': return ((int)Seg16Segments.Atsign);
case '[': return ((int)Seg16Segments.LBracket);
case '\\': return ((int)Seg16Segments.BackSlash);
case ']': return ((int)Seg16Segments.RBracket);
case '^': return ((int)Seg16Segments.Caret);
case '_': return ((int)Seg16Segments.Underline);
case '`': return ((int)Seg16Segments.Apostrophe);
case '{': return ((int)Seg16Segments.LBrace);
case '|': return ((int)Seg16Segments.Pipe);
case '}': return ((int)Seg16Segments.RBrace);
case '~': return ((int)Seg16Segments.Tilde);
case '<27>': return ((int)Seg16Segments.Pound);
case '<27>': return ((int)Seg16Segments.Degree);
case '<27>': return ((int)Seg16Segments.PlusMinus);
#endregion
default: return ((int)Seg16Segments.None);
}
}
#endregion
}
#region Enums
#region Seg16Segments
// ReSharper disable InconsistentNaming
public enum Seg16Segments : int
{
None = 0,
#region Numeric
Zero = 0xE667,
One = 0x810,
Two = 0xC3C3,
Three = 0xE1C3,
Four = 0x21C4,
Five = 0xE187,
Six = 0xE387,
Seven = 0x2043,
Eight = 0xE3C7,
Nine = 0xE1C7,
#endregion
#region Lowercase alpha
a = 0xCA80,
b = 0xA910,
c = 0x8900,
d = 0xA940,
e = 0x4680,
f = 0x912,
g = 0xB100,
h = 0x2910,
i = 0x8820,
j = 0xA840,
k = 0x1830,
l = 0x8810,
m = 0x2B80,
n = 0x2900,
o = 0xA900,
p = 0x28C,
q = 0x8895,
r = 0x900,
s = 0x9100,
t = 0x8990,
u = 0xA800,
v = 0x3000,
w = 0x3600,
x = 0x1580,
y = 0xB000,
z = 0x4480,
#endregion
#region Uppercase alpha
A = 0x23C7,
B = 0xE953,
C = 0xC207,
D = 0xE853,
E = 0xC387,
F = 0x387,
G = 0xE307,
H = 0x23C4,
I = 0xC813,
J = 0xE240,
K = 0x12A4,
L = 0xC204,
M = 0x226C,
N = 0x324C,
O = 0xE247,
P = 0x3C7,
Q = 0xF247,
R = 0x13C7,
S = 0xE187,
T = 0x813,
U = 0xE244,
V = 0x3048,
W = 0xEA44,
X = 0x1428,
Y = 0x828,
Z = 0xC423,
#endregion
#region Extended chars
Space = 0x00,
ExPoint = 0x8152,
DQuote = 0x50,
PoundSign = 0xE9D0,
DollarSign = 0xE997,
PercentSign = 0xADB5,
Ampersand = 0xD299,
SQuote = 0x10,
LParen = 0x4205,
RParen = 0xA042,
Asterisk = 0x1DB8,
PlusSign = 0x990,
Comma = 0x400,
Dash = 0x180,
FSlash = 0x420,
Colon = 0x810,
Semicolon = 0x410,
LessThan = 0x1020,
Equals = 0xC180,
GreaterThan = 0x408,
QuestionMark = 0x943,
Atsign = 0xAB47,
LBracket = 0x4205,
BackSlash = 0x1008,
RBracket = 0xA042,
Caret = 0x1400,
Underline = 0xC000,
Apostrophe = 0x8,
LBrace = 0x8892,
Pipe = 0x810,
RBrace = 0x4911,
Tilde = 0x2C,
Pound = 0xAB14,
Degree = 0x152,
PlusMinus = 0xC990,
#endregion
}
// ReSharper restore InconsistentNaming
#endregion
#endregion
}

View File

@@ -0,0 +1,318 @@
using System.Drawing;
namespace DevComponents.Instrumentation
{
public class Seg7Element : DigitalElement
{
public Seg7Element(NumericIndicator numIndicator)
: base(numIndicator, 7, 6)
{
}
#region RecalcSegments
public override void RecalcSegments()
{
CalcSegment0();
CalcSegment1();
CalcSegment2();
CalcSegment3();
CalcSegment4();
CalcSegment5();
CalcSegment6();
}
#region CalcSegment0
private void CalcSegment0()
{
Point[] pts = SegPoints[0];
pts[0].X = SegWidth + 1; pts[0].Y = 0;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = 0;
pts[2].X = ElemWidth - SegWidthHalf - 1; pts[2].Y = SegWidthHalf;
pts[3].X = pts[1].X; pts[3].Y = SegWidth;
pts[4].X = pts[0].X; pts[4].Y = SegWidth;
pts[5].X = SegWidthHalf + 1; pts[5].Y = pts[2].Y;
}
#endregion
#region CalcSegment1
private void CalcSegment1()
{
Point[] pts = SegPoints[1];
pts[0].X = 0; pts[0].Y = SegWidth + 1;
pts[1].X = SegWidthHalf; pts[1].Y = SegWidthHalf + 1;
pts[2].X = SegWidth; pts[2].Y = SegWidth + 1;
pts[3].X = SegWidth; pts[3].Y = ElemHeightHalf - SegWidthHalf - 1;
pts[4].X = 4; pts[4].Y = ElemHeightHalf - 1;
pts[5].X = 0; pts[5].Y = ElemHeightHalf - 1;
}
#endregion
#region CalcSegment2
private void CalcSegment2()
{
Point[] pts = SegPoints[2];
pts[0].X = ElemWidth - SegWidth; pts[0].Y = SegWidth + 1;
pts[1].X = ElemWidth - SegWidthHalf; pts[1].Y = SegWidthHalf + 1;
pts[2].X = ElemWidth; pts[2].Y = SegWidth + 1;
pts[3].X = ElemWidth; pts[3].Y = ElemHeightHalf - 1;
pts[4].X = ElemWidth - 4; pts[4].Y = ElemHeightHalf - 1;
pts[5].X = ElemWidth - SegWidth; pts[5].Y = ElemHeightHalf - SegWidthHalf - 1;
}
#endregion
#region CalcSegment3
private void CalcSegment3()
{
Point[] pts = SegPoints[3];
pts[0].X = SegWidth + 1; pts[0].Y = ElemHeightHalf - SegWidthHalf;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = ElemHeightHalf - SegWidthHalf;
pts[2].X = ElemWidth - 5; pts[2].Y = ElemHeightHalf;
pts[3].X = ElemWidth - SegWidth - 1; pts[3].Y = ElemHeightHalf + SegWidthHalf;
pts[4].X = SegWidth + 1; pts[4].Y = ElemHeightHalf + SegWidthHalf;
pts[5].X = 5; pts[5].Y = ElemHeightHalf;
}
#endregion
#region CalcSegment4
private void CalcSegment4()
{
Point[] pts = SegPoints[4];
pts[0].X = 0; pts[0].Y = ElemHeightHalf + 1;
pts[1].X = 4; pts[1].Y = ElemHeightHalf + 1;
pts[2].X = SegWidth; pts[2].Y = ElemHeightHalf + SegWidthHalf + 1;
pts[3].X = SegWidth; pts[3].Y = ElemHeight - SegWidth - 1;
pts[4].X = SegWidthHalf; pts[4].Y = ElemHeight - SegWidthHalf - 1;
pts[5].X = 0; pts[5].Y = ElemHeight - SegWidth - 1;
}
#endregion
#region CalcSegment5
private void CalcSegment5()
{
Point[] pts = SegPoints[5];
pts[0].X = ElemWidth - SegWidth; pts[0].Y = ElemHeightHalf + SegWidthHalf + 1;
pts[1].X = ElemWidth - 4; pts[1].Y = ElemHeightHalf + 1;
pts[2].X = ElemWidth; pts[2].Y = ElemHeightHalf + 1;
pts[3].X = ElemWidth; pts[3].Y = ElemHeight - SegWidth - 1;
pts[4].X = ElemWidth - SegWidthHalf; pts[4].Y = ElemHeight - SegWidthHalf - 1;
pts[5].X = ElemWidth - SegWidth; pts[5].Y = ElemHeight - SegWidth - 1;
}
#endregion
#region CalcSegment6
private void CalcSegment6()
{
Point[] pts = SegPoints[6];
pts[0].X = SegWidth + 1; pts[0].Y = ElemHeight - SegWidth;
pts[1].X = ElemWidth - SegWidth - 1; pts[1].Y = ElemHeight - SegWidth;
pts[2].X = ElemWidth - SegWidthHalf - 1; pts[2].Y = ElemHeight - SegWidthHalf;
pts[3].X = ElemWidth - SegWidth - 1; pts[3].Y = ElemHeight;
pts[4].X = SegWidth + 1; pts[4].Y = ElemHeight;
pts[5].X = SegWidthHalf + 1; pts[5].Y = ElemHeight - SegWidthHalf;
}
#endregion
#endregion
#region GetCharSegments
public override int GetDigitSegments(char value)
{
switch (value)
{
case '0': return ((int)Seg7Segments.Zero);
case '1': return ((int)Seg7Segments.One);
case '2': return ((int)Seg7Segments.Two);
case '3': return ((int)Seg7Segments.Three);
case '4': return ((int)Seg7Segments.Four);
case '5': return ((int)Seg7Segments.Five);
case '6': return ((int)Seg7Segments.Six);
case '7': return ((int)Seg7Segments.Seven);
case '8': return ((int)Seg7Segments.Eight);
case '9': return ((int)Seg7Segments.Nine);
case 'a': return ((int)Seg7Segments.a);
case 'b': return ((int)Seg7Segments.b);
case 'c': return ((int)Seg7Segments.c);
case 'd': return ((int)Seg7Segments.d);
case 'e': return ((int)Seg7Segments.e);
case 'f': return ((int)Seg7Segments.f);
case 'g': return ((int)Seg7Segments.g);
case 'h': return ((int)Seg7Segments.h);
case 'i': return ((int)Seg7Segments.i);
case 'j': return ((int)Seg7Segments.j);
case 'k': return ((int)Seg7Segments.k);
case 'l': return ((int)Seg7Segments.l);
case 'm': return ((int)Seg7Segments.m);
case 'n': return ((int)Seg7Segments.n);
case 'o': return ((int)Seg7Segments.o);
case 'p': return ((int)Seg7Segments.p);
case 'q': return ((int)Seg7Segments.q);
case 'r': return ((int)Seg7Segments.r);
case 's': return ((int)Seg7Segments.s);
case 't': return ((int)Seg7Segments.t);
case 'u': return ((int)Seg7Segments.u);
case 'v': return ((int)Seg7Segments.v);
case 'w': return ((int)Seg7Segments.w);
case 'x': return ((int)Seg7Segments.x);
case 'y': return ((int)Seg7Segments.y);
case 'z': return ((int)Seg7Segments.z);
case 'A': return ((int)Seg7Segments.A);
case 'B': return ((int)Seg7Segments.B);
case 'C': return ((int)Seg7Segments.C);
case 'D': return ((int)Seg7Segments.D);
case 'E': return ((int)Seg7Segments.E);
case 'F': return ((int)Seg7Segments.F);
case 'G': return ((int)Seg7Segments.G);
case 'H': return ((int)Seg7Segments.H);
case 'I': return ((int)Seg7Segments.I);
case 'J': return ((int)Seg7Segments.J);
case 'K': return ((int)Seg7Segments.K);
case 'L': return ((int)Seg7Segments.L);
case 'M': return ((int)Seg7Segments.M);
case 'N': return ((int)Seg7Segments.N);
case 'O': return ((int)Seg7Segments.O);
case 'P': return ((int)Seg7Segments.P);
case 'Q': return ((int)Seg7Segments.Q);
case 'R': return ((int)Seg7Segments.R);
case 'S': return ((int)Seg7Segments.S);
case 'T': return ((int)Seg7Segments.T);
case 'U': return ((int)Seg7Segments.U);
case 'V': return ((int)Seg7Segments.V);
case 'W': return ((int)Seg7Segments.W);
case 'X': return ((int)Seg7Segments.X);
case 'Y': return ((int)Seg7Segments.Y);
case 'Z': return ((int)Seg7Segments.Z);
case ' ': return ((int)Seg7Segments.Space);
case '-': return ((int)Seg7Segments.Dash);
case '=': return ((int)Seg7Segments.Equals);
case '(': return ((int)Seg7Segments.LParen);
case '}': return ((int)Seg7Segments.RParen);
case '[': return ((int)Seg7Segments.LBracket);
case ']': return ((int)Seg7Segments.RBracket);
case '_': return ((int)Seg7Segments.Underline);
// Add callout code to get pattern
default: return ((int)Seg7Segments.None);
}
}
#endregion
}
#region Enums
#region Seg7Segments
// ReSharper disable InconsistentNaming
public enum Seg7Segments : int
{
None = 0x0,
Zero = 0x77,
One = 0x24,
Two = 0x5D,
Three = 0x6D,
Four = 0x2E,
Five = 0x6B,
Six = 0x7B,
Seven = 0x25,
Eight = 0x7F,
Nine = 0x6F,
a = 0x7D,
b = 0x7A,
c = 0x58,
d = 0x7C,
e = 0x5F,
f = 0x1B,
g = 0x6F,
h = 0x3A,
i = 0x51,
j = 0x61,
k = 0x3E,
l = 0x50,
m = 0x31,
n = 0x38,
o = 0x78,
p = 0x1F,
q = 0x2F,
r = 0x18,
s = 0x6B,
t = 0x5A,
u = 0x70,
v = 0x70,
w = 0x46,
x = 0x3E,
y = 0x6E,
z = 0x5D,
A = 0x3F,
B = 0x7F,
C = 0x53,
D = 0x77,
E = 0x5B,
F = 0x1B,
G = 0x73,
H = 0x3E,
I = 0x24,
J = 0x74,
K = 0x3E,
L = 0x52,
M = 0x31,
N = 0x38,
O = 0x77,
P = 0x1F,
Q = 0x2F,
R = 0x13,
S = 0x6B,
T = 0x13,
U = 0x76,
V = 0x76,
W = 0x46,
X = 0x3E,
Y = 0x6E,
Z = 0x5D,
Space = 0x00,
Dash = 0x08,
Equals = 0x48,
LParen = 0x63,
RParen = 0x65,
LBracket = 0x63,
RBracket = 0x65,
Underline = 0x40,
}
// ReSharper restore InconsistentNaming
#endregion
#endregion
}

View File

@@ -0,0 +1,797 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class StateIndicator : GaugeIndicator
{
#region Private variables
private StateIndicatorStyle _Style;
private StateRangeCollection _Ranges;
private Image _Image;
private float _Angle;
private float _RoundRectangleArc;
private Color _TextColor;
private TextAlignment _TextAlignment;
private float _TextVerticalOffset;
private float _TextHorizontalOffset;
private Font _AbsFont;
#endregion
public StateIndicator()
{
InitIndicator();
}
#region InitIndicator
private void InitIndicator()
{
_Style = StateIndicatorStyle.Circular;
_RoundRectangleArc = .75f;
_TextColor = Color.Black;
_TextAlignment = TextAlignment.MiddleCenter;
BackColor.Color1 = Color.PaleGreen;
BackColor.Color2 = Color.DarkGreen;
}
#endregion
#region Public properties
#region Angle
/// <summary>
/// Gets or sets the amount to rotate the indicator, specified in degrees.
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the amount to rotate the indicator, specified in degrees.")]
public float Angle
{
get { return (_Angle); }
set
{
if (_Angle != value)
{
_Angle = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Image
/// <summary>
/// Gets or sets the Image to use
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Image to use.")]
public Image Image
{
get { return (_Image); }
set
{
if (_Image != value)
{
_Image = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Ranges
/// <summary>
/// Gets the collection of Ranges associated with the Indicator
/// </summary>
[Browsable(true), Category("Behavior")]
[Description("Indicates the collection of Ranges associated with the Indicator.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor("DevComponents.Instrumentation.Design.GaugeCollectionEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
public StateRangeCollection Ranges
{
get
{
if (_Ranges == null)
{
_Ranges = new StateRangeCollection();
_Ranges.CollectionChanged += StateRanges_CollectionChanged;
}
return (_Ranges);
}
set
{
if (_Ranges != null)
_Ranges.CollectionChanged -= StateRanges_CollectionChanged;
_Ranges = value;
if (_Ranges != null)
_Ranges.CollectionChanged += StateRanges_CollectionChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region RoundRectangleArc
/// <summary>
/// Gets or sets the RoundRectangle corner radius,
/// measured as a percentage of the width/height.
/// </summary>
[Browsable(true)]
[Category("Appearance"), DefaultValue(.75f)]
[Description("Indicates the RoundRectangle corner radius, measured as a percentage of the width/height.")]
[Editor("DevComponents.Instrumentation.Design.WidthMaxRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
public float RoundRectangleArc
{
get { return (_RoundRectangleArc); }
set
{
if (_RoundRectangleArc != value)
{
if (value < 0 || value > 1f)
throw new ArgumentException("Radius must be between 0 and 1");
_RoundRectangleArc = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Style
/// <summary>
/// Gets or sets the Indicator Style
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(StateIndicatorStyle.Circular)]
[Description("Indicates the Indicator Style.")]
public StateIndicatorStyle Style
{
get { return (_Style); }
set
{
if (_Style != value)
{
_Style = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TextAlignment
/// <summary>
/// Gets or sets the alignment of the text
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(TextAlignment.MiddleCenter)]
[Description("Indicates the alignment of the text.")]
public TextAlignment TextAlignment
{
get { return (_TextAlignment); }
set
{
if (_TextAlignment != value)
{
_TextAlignment = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TextColor
/// <summary>
/// Gets or sets the text Color
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Black")]
[Description("Indicates the text Color.")]
public Color TextColor
{
get { return (_TextColor); }
set
{
if (_TextColor != value)
{
_TextColor = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TextHorizontalOffset
/// <summary>
/// Gets or sets the horizontal distance to offset the Indicator Text, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the horizontal distance to offset the Indicator Text, measured as a percentage.")]
public float TextHorizontalOffset
{
get { return (_TextHorizontalOffset); }
set
{
if (_TextHorizontalOffset != value)
{
_TextHorizontalOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TextVerticalOffset
/// <summary>
/// Gets or sets the vertical distance to offset the Indicator Text, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the vertical distance to offset the Indicator Text, measured as a percentage.")]
public float TextVerticalOffset
{
get { return (_TextVerticalOffset); }
set
{
if (_TextVerticalOffset != value)
{
_TextVerticalOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsFont
internal override Font AbsFont
{
get
{
if (AutoSize == false)
return (Font);
if (_AbsFont == null)
{
int n = Math.Min(Bounds.Width, Bounds.Height);
float emSize = Font.SizeInPoints;
emSize = (emSize / 40) * n;
AbsFont = new Font(Font.FontFamily, emSize, Font.Style);
}
return (_AbsFont);
}
set
{
if (_AbsFont != null)
_AbsFont.Dispose();
_AbsFont = value;
}
}
#endregion
#endregion
#region Event processing
#region StateRange processing
void StateRanges_CollectionChanged(object sender, EventArgs e)
{
foreach (StateRange range in _Ranges)
{
range.StateIndicator = this;
range.IndicatorRangeChanged -= StateRange_ItemChanged;
range.IndicatorRangeChanged += StateRange_ItemChanged;
}
}
void StateRange_ItemChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
Size size = Bounds.Size;
base.RecalcLayout();
if (size.Equals(Bounds.Size) == false)
AbsFont = null;
}
}
#endregion
#region OnPaint
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
RecalcLayout();
if (GaugeControl.OnPreRenderIndicator(e, this) == false)
{
InterpolationMode im = g.InterpolationMode;
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.TranslateTransform(Center.X, Center.Y);
g.RotateTransform(_Angle % 360);
Rectangle r = new Rectangle(0, 0, Bounds.Width, Bounds.Height);
r.X -= Bounds.Width / 2;
r.Y -= Bounds.Height / 2;
StateRange range = GetStateRange();
DrawStateImage(g, r, range);
DrawStateText(g, r, range);
GaugeControl.OnPostRenderIndicator(e, this);
g.ResetTransform();
g.InterpolationMode = im;
}
}
#region GetStateRange
private StateRange GetStateRange()
{
return (_Ranges != null ? _Ranges.GetValueRange(DValue) : null);
}
#endregion
#region DrawStateImage
private void DrawStateImage(Graphics g, Rectangle r, StateRange range)
{
Image image = (range != null) ? range.Image : _Image;
if (image != null)
{
if (AutoSize == true)
{
g.DrawImage(image, r);
}
else
{
r.X += (r.Width - image.Width) / 2;
r.Y += (r.Height - image.Height) / 2;
g.DrawImageUnscaled(image, r);
}
}
else
{
GradientFillColor fillColor =
(range != null) ? range.BackColor : BackColor;
using (GraphicsPath path = GetStatePath(r))
RenderBackPath(g, path, r, fillColor);
}
}
#region GetStatePath
private GraphicsPath GetStatePath(Rectangle r)
{
switch (_Style)
{
case StateIndicatorStyle.Circular:
return (GetCircularState(r));
case StateIndicatorStyle.Rectangular:
return (GetRectState(r));
default:
return (GetRoundRectState(r));
}
}
#endregion
#region GetCircularState
private GraphicsPath GetCircularState(Rectangle bounds)
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(bounds);
return (path);
}
#endregion
#region GetRectState
private GraphicsPath GetRectState(Rectangle bounds)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(bounds);
return (path);
}
#endregion
#region GetRoundRectState
private GraphicsPath GetRoundRectState(Rectangle bounds)
{
GraphicsPath path = new GraphicsPath();
int m = Math.Min(bounds.Width, bounds.Height);
int n = (int)(m * _RoundRectangleArc) + 1;
Rectangle t = new Rectangle(bounds.Right - n, bounds.Bottom - n, n, n);
path.AddArc(t, 0, 90);
t.X = bounds.X;
path.AddArc(t, 90, 90);
t.Y = bounds.Y;
path.AddArc(t, 180, 90);
t.X = bounds.Right - n;
path.AddArc(t, 270, 90);
path.CloseAllFigures();
return (path);
}
#endregion
#region RenderBackPath
private void RenderBackPath(Graphics g,
GraphicsPath path, Rectangle bounds, GradientFillColor fillColor)
{
Rectangle r = bounds;
GradientFillType fillType = fillColor.GradientFillType;
if (fillColor.End.IsEmpty)
{
fillType = GradientFillType.None;
}
else
{
if (fillColor.GradientFillType == GradientFillType.Auto)
fillType = GradientFillType.Center;
}
switch (fillType)
{
case GradientFillType.Angle:
using (Brush br = fillColor.GetBrush(r))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.StartToEnd:
using (Brush br = fillColor.GetBrush(r, 90))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.HorizontalCenter:
r.Height /= 2;
if (r.Height <= 0)
r.Height = 1;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.VerticalCenter:
r.Width /= 2;
if (r.Width <= 0)
r.Width = 1;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.Center:
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterPoint = new PointF(bounds.X + bounds.Width / 2, bounds.Y + bounds.Height / 2);
br.CenterColor = fillColor.Start;
br.SurroundColors = new Color[] { fillColor.End };
g.FillPath(br, path);
}
break;
default:
using (Brush br = new SolidBrush(fillColor.Start))
g.FillPath(br, path);
break;
}
if (fillColor.BorderWidth > 0 && fillColor.BorderColor.IsEmpty == false)
{
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
g.DrawPath(pen, path);
}
else
{
if (fillType == GradientFillType.Center)
{
using (Pen pen = new Pen(fillColor.End))
g.DrawPath(pen, path);
}
}
}
#endregion
#endregion
#region DrawStateText
private void DrawStateText(Graphics g, Rectangle r, StateRange range)
{
string text = (range != null)
? range.Text : GetOverrideString();
if (string.IsNullOrEmpty(text) == false)
{
using (StringFormat sf = new StringFormat())
{
SetStringAlignment(sf);
Color color = _TextColor;
if (range != null)
{
color = range.TextColor;
int dx = (int)(r.Width * range.TextHorizontalOffset);
int dy = (int)(r.Height * range.TextVerticalOffset);
r.Offset(dx, dy);
}
else
{
int dx = (int)(r.Width * _TextHorizontalOffset);
int dy = (int)(r.Height * _TextVerticalOffset);
r.Offset(dx, dy);
}
using (Brush br = new SolidBrush(color))
g.DrawString(text, AbsFont, br, r, sf);
}
}
}
#region SetStringAlignment
private void SetStringAlignment(StringFormat sf)
{
switch (_TextAlignment)
{
case TextAlignment.TopLeft:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.TopCenter:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.TopRight:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Far;
break;
case TextAlignment.MiddleLeft:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.MiddleCenter:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.MiddleRight:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Far;
break;
case TextAlignment.BottomLeft:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.BottomCenter:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.BottomRight:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Far;
break;
}
}
#endregion
#endregion
#endregion
#endregion
#region Refresh
internal void Refresh()
{
if (NeedRecalcLayout == false)
OnGaugeItemChanged(false);
}
#endregion
#region Contains
internal override bool Contains(Point pt)
{
using (GraphicsPath path = GetStatePath(Bounds))
{
Matrix matrix = new Matrix();
matrix.RotateAt(_Angle, Center);
path.Transform(matrix);
return (path.IsVisible(pt));
}
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
StateIndicator c = copy as StateIndicator;
if (c != null)
{
base.CopyToItem(c);
c.Angle = _Angle;
c.Image = _Image;
if (_Ranges != null)
c.Ranges = (StateRangeCollection)_Ranges.Clone();
c.RoundRectangleArc = _RoundRectangleArc;
c.Style = _Style;
c.TextAlignment = _TextAlignment;
c.TextColor = _TextColor;
c.TextHorizontalOffset = _TextHorizontalOffset;
c.TextVerticalOffset = _TextVerticalOffset;
}
}
#endregion
}
#region Enums
public enum StateIndicatorStyle
{
Rectangular,
RoundedRectangular,
Circular
}
#endregion
}

View File

@@ -0,0 +1,251 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class StateRangeCollection : GenericCollection<StateRange>
{
#region GetValueRange
public StateRange GetValueRange(double value)
{
foreach (StateRange range in this)
{
if (value >= range.StartValue && value <= range.EndValue)
return (range);
}
return (null);
}
#endregion
#region ICloneable Members
public override object Clone()
{
StateRangeCollection copy = new StateRangeCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(StateRangeCollection copy)
{
foreach (StateRange item in this)
{
StateRange ic = new StateRange();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
public class StateRange : IndicatorRange
{
#region Private variables
private Image _Image;
private StateIndicator _StateIndicator;
private string _Text;
private Color _TextColor;
private float _TextVerticalOffset;
private float _TextHorizontalOffset;
#endregion
public StateRange()
{
TextColor = Color.Black;
}
#region Public properties
#region Image
/// <summary>
/// Gets or sets the Image to use
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Image to use.")]
public Image Image
{
get { return (_Image); }
set
{
if (_Image != value)
{
_Image = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region StateIndicator
/// <summary>
/// Gets or sets the StateIndicator
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public StateIndicator StateIndicator
{
get { return (_StateIndicator); }
internal set { _StateIndicator = value; }
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text to be displayed
/// </summary>
[Browsable(true), Category("Behavior"), DefaultValue(null)]
[Description("Indicates the text to be displayed.")]
public string Text
{
get { return (_Text); }
set
{
if (_Text != value)
{
_Text = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region TextColor
/// <summary>
/// Gets or sets the text Color
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Black")]
[Description("Indicates the text Color.")]
public Color TextColor
{
get { return (_TextColor); }
set
{
if (_TextColor != value)
{
_TextColor = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region TextHorizontalOffset
/// <summary>
/// Gets or sets the horizontal distance to offset the Indicator Text, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the horizontal distance to offset the Indicator Text, measured as a percentage.")]
public float TextHorizontalOffset
{
get { return (_TextHorizontalOffset); }
set
{
if (_TextHorizontalOffset != value)
{
_TextHorizontalOffset = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#region TextVerticalOffset
/// <summary>
/// Gets or sets the vertical distance to offset the Indicator Text, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the vertical distance to offset the Indicator Text, measured as a percentage.")]
public float TextVerticalOffset
{
get { return (_TextVerticalOffset); }
set
{
if (_TextVerticalOffset != value)
{
_TextVerticalOffset = value;
OnIndicatorRangeChanged();
}
}
}
#endregion
#endregion
#region ICloneable Members
public override object Clone()
{
StateRange copy = new StateRange();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
StateRange c = copy as StateRange;
if (c != null)
{
base.CopyToItem(c);
c.Image = _Image;
c.Text = _Text;
c.TextColor = _TextColor;
c.TextHorizontalOffset = _TextHorizontalOffset;
c.TextVerticalOffset = _TextVerticalOffset;
}
}
#endregion
}
}

View File

@@ -0,0 +1,394 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeImages
/// </summary>
public class GaugeImageCollection : GenericCollection<GaugeImage>
{
}
public class GaugeImage : GaugeItem
{
#region Private variables
private Image _Image;
private SizeF _Size;
private PointF _Location;
private float _Angle;
private bool _AutoFit;
private Rectangle _Bounds;
private Point _Center;
private bool _UnderScale;
private GaugeControl _GaugeControl;
#endregion
public GaugeImage(GaugeControl gaugeControl)
: this()
{
_GaugeControl = gaugeControl;
InitGagueImage();
}
public GaugeImage()
{
InitGagueImage();
}
#region InitGagueImage
private void InitGagueImage()
{
_Size = new SizeF(.1f, .1f);
_Location = new PointF(.3f, .5f);
_UnderScale = true;
}
#endregion
#region Public properties
#region Angle
/// <summary>
/// Gets or sets the amount to rotate the image, specified in degrees
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the amount to rotate the image, specified in degrees.")]
public float Angle
{
get { return (_Angle); }
set
{
if (_Angle != value)
{
_Angle = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region AutoFit
/// <summary>
/// Gets or sets whether the image will be stretched to fit the given area
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(false)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines whether the image will be stretched to fit the given area.")]
public bool AutoFit
{
get { return (_AutoFit); }
set
{
if (_AutoFit != value)
{
_AutoFit = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Image
/// <summary>
/// Gets or sets the Image to be displayed
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Image to be displayed.")]
public Image Image
{
get { return (_Image); }
set
{
if (_Image != value)
{
_Image = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Location
/// <summary>
/// Gets or sets the location of the image area, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.LocationEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the location of the image area, specified as a percentage.")]
[TypeConverter(typeof(PointFConverter))]
public PointF Location
{
get { return (_Location); }
set
{
if (_Location != value)
{
_Location = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeLocation()
{
return (_Location.X != .3f || _Location.Y != .5f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetLocation()
{
_Location = new PointF(.3f, .5f);
}
#endregion
#region Size
/// <summary>
/// Gets or sets the size of the image, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.SizeEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the size of the image, specified as a percentage.")]
public SizeF Size
{
get { return (_Size); }
set
{
if (_Size != value)
{
_Size = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSize()
{
return (_Size.Width != .2f || _Size.Height != .2f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSize()
{
_Size = new SizeF(.2f, .2f);
}
#endregion
#region UnderScale
/// <summary>
/// Gets or sets whether the image is displayed under the scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(true)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates whether the image is displayed under the scale.")]
public bool UnderScale
{
get { return (_UnderScale); }
set
{
if (_UnderScale != value)
{
_UnderScale = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region GaugeControl
internal GaugeControl GaugeControl
{
get { return (_GaugeControl); }
set { _GaugeControl = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
bool autoCenter = _GaugeControl.Frame.AutoCenter;
Size size = _GaugeControl.GetAbsSize(_Size, autoCenter);
_Center = _GaugeControl.GetAbsPoint(_Location, autoCenter);
_Bounds = new Rectangle(
_Center.X - size.Width / 2, _Center.Y - size.Height / 2,
size.Width, size.Height);
}
}
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
RecalcLayout();
Graphics g = e.Graphics;
if (_Bounds.Width > 0 && _Bounds.Height > 0)
{
g.TranslateTransform(_Center.X, _Center.Y);
g.RotateTransform(_Angle % 360);
Rectangle r = new Rectangle(0, 0, _Bounds.Width, _Bounds.Height);
r.X -= _Bounds.Width / 2;
r.Y -= _Bounds.Height / 2;
if (Image != null)
{
if (_AutoFit == false)
{
r = new Rectangle(0, 0, _Image.Width, _Image.Height);
r.X -= _Image.Width / 2;
r.Y -= _Image.Height / 2;
}
g.DrawImage(_Image, r);
}
else
{
g.FillRectangle(Brushes.White, r);
g.DrawLine(Pens.Red, new Point(r.X, r.Y), new Point(r.Right, r.Bottom));
g.DrawLine(Pens.Red, new Point(r.X, r.Bottom), new Point(r.Right, r.Y));
g.DrawRectangle(Pens.Black, r);
}
g.ResetTransform();
}
}
#endregion
#region Contains
internal bool Contains(Point pt)
{
if (Angle == 0)
{
return (_Bounds.Contains(pt));
}
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(Bounds);
Matrix matrix = new Matrix();
matrix.RotateAt(_Angle, _Center);
path.Transform(matrix);
return (path.IsVisible(pt));
}
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeImage copy = new GaugeImage();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeImage c = copy as GaugeImage;
if (c != null)
{
base.CopyToItem(c);
c.Angle = _Angle;
c.AutoFit = _AutoFit;
c.Image = _Image;
c.Location = _Location;
c.Size = _Size;
c.UnderScale = _UnderScale;
}
}
#endregion
}
}

View File

@@ -0,0 +1,366 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class GaugeItemCollection : GenericCollection<GaugeItem>
{
}
public class GaugeItem : IDisposable, ICloneable
{
#region Events
public event EventHandler<EventArgs> GaugeItemChanged;
#endregion
#region Private variables
private string _Name;
private string _Tooltip;
private object _Tag;
private bool _NeedRecalcLayout;
private bool _Visible;
#endregion
public GaugeItem()
{
_NeedRecalcLayout = true;
_Visible = true;
}
#region Public properties
#region Name
/// <summary>
/// Gets or sets the Name associated with the item
/// </summary>
[Browsable(true), Category("Misc."), DefaultValue(null)]
[Description("Indicates the Name associated with the item.")]
[ParenthesizePropertyName(true)]
public string Name
{
get { return (_Name); }
set { _Name = value; }
}
#endregion
#region Tag
/// <summary>
/// Gets or sets the user defined Tag associated with the item
/// </summary>
[Browsable(false), DefaultValue(0)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public object Tag
{
get { return (_Tag); }
set { _Tag = value; }
}
#endregion
#region Tooltip
/// <summary>
/// Gets or sets the Tooltip associated with the item
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Tooltip associated with the item.")]
public string Tooltip
{
get { return (_Tooltip); }
set { _Tooltip = value; }
}
#endregion
#region Visible
/// <summary>
/// Gets or sets the item Visibility state.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates the item Visibility state.")]
[ParenthesizePropertyName(true)]
public virtual bool Visible
{
get { return (_Visible); }
set
{
if (_Visible != value)
{
_Visible = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region NeedRecalcLayout
internal virtual bool NeedRecalcLayout
{
get { return (_NeedRecalcLayout); }
set { _NeedRecalcLayout = value; }
}
#endregion
#endregion
#region RecalcLayout
public virtual void RecalcLayout()
{
_NeedRecalcLayout = false;
}
#endregion
#region PerformLayout
/// <summary>
/// Causes the item to recalculate its layout
/// </summary>
public virtual void PerformLayout()
{
_NeedRecalcLayout = true;
RecalcLayout();
}
#endregion
#region OnPaint
public virtual void OnPaint(PaintEventArgs e)
{
if (_NeedRecalcLayout == true)
RecalcLayout();
}
#endregion
#region OnGaugeItemChanged
protected virtual void OnGaugeItemChanged()
{
if (GaugeItemChanged != null)
GaugeItemChanged(this, EventArgs.Empty);
}
protected virtual void OnGaugeItemChanged(bool recalc)
{
if (recalc == true)
NeedRecalcLayout = true;
if (GaugeItemChanged != null)
GaugeItemChanged(this, EventArgs.Empty);
}
#endregion
#region FindItem
internal virtual GaugeItem FindItem(Point pt)
{
return (null);
}
#endregion
#region OnMouseMove
internal virtual void OnMouseMove(MouseEventArgs e, bool mouseDown)
{
}
#endregion
#region OnMouseEnter
internal virtual void OnMouseEnter()
{
}
#endregion
#region OnMouseLeave
internal virtual void OnMouseLeave()
{
}
#endregion
#region OnMouseDown
internal virtual void OnMouseDown(MouseEventArgs e)
{
}
#endregion
#region OnMouseUp
internal virtual void OnMouseUp(MouseEventArgs e)
{
}
#endregion
#region GetDisplayTemplateText
internal string GetitemTemplateText(GaugeControl gauge)
{
string s = _Tooltip;
if (String.IsNullOrEmpty(s) == true)
return (s);
Regex r = new Regex(
@"\[(?<key>[^\{\]]+)" +
@"(\{(?<data>[^\}\]]+)\})*" +
@"\]");
MatchCollection mc = r.Matches(s);
if (mc.Count <= 0)
return (s);
int index = 0;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < mc.Count; i++)
{
Match ma = mc[i];
if (ma.Index > index)
sb.Append(s.Substring(index, ma.Index - index));
string t1 = mc[i].Groups["key"].Value;
string t2 = mc[i].Groups["data"].Value;
ProcessTemplateText(gauge, sb, t1, t2);
index = ma.Index + ma.Length;
}
if (s.Length > index)
sb.Append(s.Substring(index));
return (sb.ToString());
}
#endregion
#region AppendTemplateText
protected virtual void ProcessTemplateText(
GaugeControl gauge, StringBuilder sb, string key, string data)
{
switch (key)
{
case "Name":
sb.Append(string.IsNullOrEmpty(data)
? _Name
: String.Format("{0:" + data + "}", _Name));
break;
case "Tag":
sb.Append(string.IsNullOrEmpty(data)
? Tag.ToString()
: String.Format("{0:" + data + "}", Tag));
break;
default:
sb.Append(gauge.OnGetDisplayTemplateText(this, key, data));
break;
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
OnDispose();
}
protected virtual void OnDispose()
{
}
#endregion
#region ICloneable Members
public virtual object Clone()
{
GaugeItem copy = new GaugeItem();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public virtual void CopyToItem(GaugeItem copy)
{
copy.Name = _Name;
copy.Tag = _Tag;
copy.Tooltip = _Tooltip;
copy.Visible = _Visible;
}
#endregion
}
#region Enums
public enum DisplayPlacement
{
Near,
Center,
Far
}
public enum DisplayLevel
{
Top,
Bottom
}
public enum ColorSourceFillEntry
{
MajorTickMark,
MinorTickMark,
Pointer,
Cap
}
#endregion
}

View File

@@ -0,0 +1,521 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DevComponents.Instrumentation
{
internal class GaugeMarker : IDisposable
{
#region Private variables
private List<BitmapEntry> _Bitmaps;
#endregion
public GaugeMarker()
{
_Bitmaps = new List<BitmapEntry>();
}
#region Clear
public void Clear()
{
foreach (BitmapEntry entry in _Bitmaps)
entry.Bitmap.Dispose();
_Bitmaps.Clear();
}
#endregion
#region FindBitmap
public Bitmap FindBitmap(GradientFillColor fillColor)
{
foreach (BitmapEntry entry in _Bitmaps)
{
if (entry.FillColor.IsEqualTo(fillColor) == true)
return (entry.Bitmap);
}
return (null);
}
#endregion
#region GetMarkerBitmap
public Bitmap GetMarkerBitmap(Graphics g,
GaugeMarkerStyle style, GradientFillColor fillColor, int width, int length)
{
Bitmap bitmap = FindBitmap(fillColor);
if (bitmap == null)
{
width = Math.Max(width, 3);
length = Math.Max(length, 3);
bitmap = new Bitmap(width, length, g);
_Bitmaps.Add(new BitmapEntry(fillColor, bitmap));
using (Graphics gBmp = Graphics.FromImage(bitmap))
{
gBmp.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle r = new Rectangle();
r.Height = length;
r.Width = width;
using (GraphicsPath path = GetMarkerPath(style, r))
FillMarkerPath(gBmp, path, r, style, fillColor);
}
}
return (bitmap);
}
#endregion
#region FillMarkerPath
internal void FillMarkerPath(Graphics g, GraphicsPath path,
Rectangle r, GaugeMarkerStyle style, GradientFillColor fillColor)
{
GradientFillType fillType = GetMarkerFillType(style, fillColor);
switch (fillType)
{
case GradientFillType.Angle:
using (Brush br = fillColor.GetBrush(r))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.StartToEnd:
using (Brush br = fillColor.GetBrush(r, 90))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.HorizontalCenter:
r.Height /= 2;
if (r.Height <= 0)
r.Height = 1;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.VerticalCenter:
r.Width /= 2;
if (r.Width <= 0)
r.Width = 1;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.Center:
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = fillColor.Start;
br.SurroundColors = new Color[] { fillColor.End };
g.FillPath(br, path);
}
break;
default:
using (Brush br = new SolidBrush(fillColor.Start))
g.FillPath(br, path);
break;
}
if (fillColor.BorderWidth > 0)
{
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
#endregion
#region GetMarkerFillType
private GradientFillType GetMarkerFillType(GaugeMarkerStyle style, GradientFillColor fillColor)
{
if (fillColor.End.IsEmpty == true)
return (GradientFillType.None);
if (fillColor.GradientFillType == GradientFillType.Auto)
{
switch (style)
{
case GaugeMarkerStyle.Circle:
case GaugeMarkerStyle.Star5:
case GaugeMarkerStyle.Star7:
return (GradientFillType.Center);
default:
return (GradientFillType.VerticalCenter);
}
}
return (fillColor.GradientFillType);
}
#endregion
#region GetMarkerPath
internal GraphicsPath GetMarkerPath(GaugeMarkerStyle style, Rectangle r)
{
r.Inflate(-1, -1);
if (r.Width > 0 && r.Height > 0)
{
switch (style)
{
case GaugeMarkerStyle.Circle:
return (GetCirclePath(r));
case GaugeMarkerStyle.Diamond:
return (GetDiamondPath(r));
case GaugeMarkerStyle.Hexagon:
return (GetPolygonPath(r, 6, 90));
case GaugeMarkerStyle.Pentagon:
return (GetPolygonPath(r, 5, 90));
case GaugeMarkerStyle.Rectangle:
return (GetRectanglePath(r));
case GaugeMarkerStyle.Star5:
return (GetStarPath(r, 5));
case GaugeMarkerStyle.Star7:
return (GetStarPath(r, 7));
case GaugeMarkerStyle.Trapezoid:
return (GetTrapezoidPath(r));
case GaugeMarkerStyle.Triangle:
return (GetTrianglePath(r));
case GaugeMarkerStyle.Wedge:
return (GetWedgePath(r));
default:
return (GetRectanglePath(r));
}
}
return (null);
}
#region GetCirclePath
private GraphicsPath GetCirclePath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
path.AddEllipse(r);
return (path);
}
#endregion
#region GetDiamondPath
private GraphicsPath GetDiamondPath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int dx = r.Width / 2;
int dy = r.Height / 2;
Point[] pts = {
new Point(r.Left + dx, r.Top),
new Point(r.Right, r.Top + dy),
new Point(r.Left + dx, r.Bottom),
new Point(r.Left, r.Top + dy),
};
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#region GetPolygonPath
private GraphicsPath GetPolygonPath(Rectangle r, int sides, float angle)
{
GraphicsPath path = new GraphicsPath();
double dx = (double)r.Width / 2;
double radians = GetRadians(angle);
double delta = GetRadians((float)360 / sides);
Point[] pts = new Point[sides];
for (int i = 0; i < sides; i++)
{
pts[i] = new Point(
(int)(dx * Math.Cos(radians) + dx + r.X),
(int)(dx * Math.Sin(radians) + dx + r.Y));
radians += delta;
}
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#region GetRectanglePath
private GraphicsPath GetRectanglePath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(r);
return (path);
}
#endregion
#region GetStarPath
private GraphicsPath GetStarPath(Rectangle r, int points)
{
GraphicsPath path = new GraphicsPath();
PointF[] pts = new PointF[2 * points];
double rx1 = r.Width / 2;
double ry1 = r.Height / 2;
if (rx1 < 2)
rx1 = 2;
if (ry1 < 2)
ry1 = 2;
double rx2 = rx1 / 2;
double ry2 = ry1 / 2;
double cx = r.X + rx1;
double cy = r.Y + ry1;
double theta = GetRadians(90);
double dtheta = Math.PI / points;
for (int i = 0; i < 2 * points; i += 2)
{
pts[i] = new PointF(
(float)(cx + rx1 * Math.Cos(theta)),
(float)(cy + ry1 * Math.Sin(theta)));
theta += dtheta;
pts[i + 1] = new PointF(
(float)(cx + rx2 * Math.Cos(theta)),
(float)(cy + ry2 * Math.Sin(theta)));
theta += dtheta;
}
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#region GetTrianglePath
private GraphicsPath GetTrianglePath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int dx = r.Width / 2;
Point[] pts = {
new Point(r.Left, r.Top),
new Point(r.Right, r.Top),
new Point(r.Left + dx, r.Bottom),
};
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#region GetTrapezoidPath
private GraphicsPath GetTrapezoidPath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int dx = (int)(r.Width * .28f);
if (dx <= 0)
dx = 1;
Point[] pts = {
new Point(r.Left, r.Top),
new Point(r.Right, r.Top),
new Point(r.Right - dx, r.Bottom),
new Point(r.Left + dx, r.Bottom),
};
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#region GetWedgePath
private GraphicsPath GetWedgePath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int dx = r.Width / 2;
if ((r.Width % 2) == 1)
dx++;
if (dx <= 0)
dx = 1;
int dy = (int)Math.Sqrt((r.Width * r.Width) - (dx * dx));
int y = Math.Max(r.Y, r.Bottom - dy);
Point[] pts = {
new Point(r.X, r.Top),
new Point(r.Right, r.Top),
new Point(r.Right, y),
new Point(r.X + dx, r.Bottom),
new Point(r.X, y)
};
path.AddPolygon(pts);
path.CloseAllFigures();
return (path);
}
#endregion
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
internal double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region BitmapEntry
private class BitmapEntry
{
public GradientFillColor FillColor;
public Bitmap Bitmap;
public BitmapEntry(GradientFillColor fillColor, Bitmap bitmap)
{
FillColor = (GradientFillColor)fillColor.Clone();
Bitmap = bitmap;
}
}
#endregion
#region IDisposable Members
public void Dispose()
{
Clear();
}
#endregion
}
#region Enums
public enum GaugeMarkerStyle
{
Circle,
Diamond,
Hexagon,
Pentagon,
Rectangle,
Star5,
Star7,
Trapezoid,
Triangle,
Wedge,
None
}
#endregion
}

View File

@@ -0,0 +1,757 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeText items
/// </summary>
public class GaugeTextCollection : GenericCollection<GaugeText>
{
}
public class GaugeText : GaugeItem
{
#region Private variables
private string _Text;
private SizeF _Size;
private PointF _Location;
private float _Angle;
private Font _Font;
private Font _AbsFont;
private bool _AutoSize;
private TextAlignment _TextAlignment;
private Color _ForeColor;
private GradientFillColor _BackColor;
private Rectangle _Bounds;
private Point _Center;
private bool _UnderScale;
private GaugeControl _GaugeControl;
#endregion
public GaugeText(GaugeControl gaugeControl)
: this()
{
_GaugeControl = gaugeControl;
InitGaugeText();
}
public GaugeText()
{
InitGaugeText();
}
#region InitGagueText
private void InitGaugeText()
{
_Text = "Text";
BackColor.BorderColor = Color.Black;
_ForeColor = Color.Black;
_Size = new SizeF(.2f, .2f);
_Location = new PointF(.3f, .5f);
_AutoSize = true;
_TextAlignment = TextAlignment.MiddleCenter;
_UnderScale = true;
}
#endregion
#region Public properties
#region Angle
/// <summary>
/// Gets or sets the amount to rotate the text, specified in degrees.
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the amount to rotate the text, specified in degrees.")]
public float Angle
{
get { return (_Angle); }
set
{
if (_Angle != value)
{
_Angle = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region AutoSize
/// <summary>
/// Gets or sets whether the text Font size is auto sized
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(true)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates whether the text Font size is auto sized.")]
public bool AutoSize
{
get { return (_AutoSize); }
set
{
if (_AutoSize != value)
{
_AutoSize = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region BackColor
/// <summary>
/// Gets or sets the text BackColor
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the BackColor.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor BackColor
{
get
{
if (_BackColor == null)
{
_BackColor = new GradientFillColor();
_BackColor.ColorTableChanged += BackColor_ColorTableChanged;
}
return (_BackColor);
}
set
{
if (_BackColor != null)
_BackColor.ColorTableChanged -= BackColor_ColorTableChanged;
_BackColor = value;
if (_BackColor != null)
_BackColor.ColorTableChanged += BackColor_ColorTableChanged;
OnGaugeItemChanged();
}
}
#endregion
#region Font
/// <summary>
/// Gets or sets the text Font
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the text Font.")]
public Font Font
{
get
{
if (_Font == null)
_Font = new Font("Microsoft SanSerif", 12);
return (_Font);
}
set
{
if (_Font != null)
_Font.Dispose();
_Font = value;
AbsFont = null;
OnGaugeItemChanged(true);
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeFont()
{
if (_Font == null)
return (false);
using (Font font = new Font("Microsoft SanSerif", 12))
return (_Font.Equals(font) == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetFont()
{
Font = new Font("Microsoft SanSerif", 12);
}
#endregion
#region ForeColor
/// <summary>
/// Gets or sets the text ForeColor
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Black")]
[Description("Indicates the text ForeColor.")]
public Color ForeColor
{
get { return (_ForeColor); }
set
{
if (_ForeColor != value)
{
_ForeColor = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Location
/// <summary>
/// Gets or sets the center location of the text area, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.LocationEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the center location of the text area, specified as a percentage.")]
[TypeConverter(typeof(PointFConverter))]
public PointF Location
{
get { return (_Location); }
set
{
if (_Location != value)
{
_Location = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeLocation()
{
return (_Location.X != .3f || _Location.Y != .5f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetLocation()
{
_Location = new PointF(.3f, .5f);
}
#endregion
#region Size
/// <summary>
/// Gets or sets the size of the text area, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.SizeEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the size of the text area, specified as a percentage.")]
public SizeF Size
{
get { return (_Size); }
set
{
if (_Size != value)
{
_Size = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSize()
{
return (_Size.Width != .2f || _Size.Height != .2f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSize()
{
_Size = new SizeF(.2f, .2f);
}
#endregion
#region Text
/// <summary>
/// Gets or sets the text to be displayed
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue("Text")]
[Description("Indicates the text to be displayed.")]
public string Text
{
get { return (_Text); }
set
{
if (_Text != value)
{
_Text = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TextAlignment
/// <summary>
/// Gets or sets the alignment of the text
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(TextAlignment.MiddleCenter)]
[Description("Indicates the alignment of the text.")]
public TextAlignment TextAlignment
{
get { return (_TextAlignment); }
set
{
if (_TextAlignment != value)
{
_TextAlignment = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region UnderScale
/// <summary>
/// Gets or sets whether the text is displayed under the scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(true)]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates whether the text is displayed under the scale.")]
public bool UnderScale
{
get { return (_UnderScale); }
set
{
if (_UnderScale != value)
{
_UnderScale = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsFont
internal Font AbsFont
{
get
{
if (_AutoSize == false)
return (Font);
if (_AbsFont == null)
{
int n = (_GaugeControl.Frame.AutoCenter == true)
? Math.Min(_GaugeControl.Width, _GaugeControl.Height) / 2
: Math.Max(_GaugeControl.Width, _GaugeControl.Height) / 3;
float emSize = Font.SizeInPoints;
emSize = (emSize / 170) * n;
AbsFont = new Font(_Font.FontFamily, emSize, _Font.Style);
}
return (_AbsFont);
}
set
{
if (_AbsFont != null)
_AbsFont.Dispose();
_AbsFont = value;
}
}
#endregion
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region GaugeControl
internal GaugeControl GaugeControl
{
get { return (_GaugeControl); }
set { _GaugeControl = value; }
}
#endregion
#endregion
#region Event processing
void BackColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
bool autoCenter = _GaugeControl.Frame.AutoCenter;
Size size = _GaugeControl.GetAbsSize(_Size, autoCenter);
if (size.Equals(_Bounds.Size) == false)
AbsFont = null;
_Center = _GaugeControl.GetAbsPoint(_Location, autoCenter);
_Bounds = new Rectangle(
_Center.X - size.Width / 2, _Center.Y - size.Height / 2,
size.Width, size.Height);
}
}
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
RecalcLayout();
Graphics g = e.Graphics;
if (_Bounds.Width > 0 && _Bounds.Height > 0)
{
g.TranslateTransform(_Center.X, _Center.Y);
g.RotateTransform(_Angle % 360);
Rectangle r = new Rectangle(0, 0, _Bounds.Width, _Bounds.Height);
r.X -= _Bounds.Width / 2;
r.Y -= _Bounds.Height / 2;
if (_BackColor.Color1.IsEmpty == false)
PaintBackColor(e, r);
if (_BackColor.BorderWidth > 0)
{
using (Pen pen = new Pen(_BackColor.BorderColor, _BackColor.BorderWidth))
g.DrawRectangle(pen, r);
}
if (string.IsNullOrEmpty(_Text) == false)
{
using (StringFormat sf = new StringFormat())
{
SetStringAlignment(sf);
if (_BackColor.BorderWidth > 0)
r.Inflate(-(_BackColor.BorderWidth + 1), -(_BackColor.BorderWidth + 1));
using (Brush br = new SolidBrush(_ForeColor))
g.DrawString(_Text, AbsFont, br, r, sf);
}
}
g.ResetTransform();
}
}
#region PaintBackColor
private void PaintBackColor(PaintEventArgs e, Rectangle r)
{
Graphics g = e.Graphics;
GradientFillType fillType = _BackColor.GradientFillType;
if (_BackColor.End.IsEmpty == true || (_BackColor.Color1 == _BackColor.Color2))
fillType = GradientFillType.None;
switch (fillType)
{
case GradientFillType.Auto:
case GradientFillType.Angle:
using (Brush br = _BackColor.GetBrush(r))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
break;
case GradientFillType.StartToEnd:
using (Brush br = _BackColor.GetBrush(r, 90))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
break;
case GradientFillType.HorizontalCenter:
Rectangle t1 = r;
t1.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t1, _BackColor.Start, _BackColor.End, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
break;
case GradientFillType.VerticalCenter:
Rectangle t2 = r;
t2.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t2, _BackColor.Start, _BackColor.End, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
break;
case GradientFillType.Center:
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = _BackColor.Start;
br.SurroundColors = new Color[] {_BackColor.End};
g.FillRectangle(br, r);
}
}
break;
default:
using (Brush br = new SolidBrush(_BackColor.Start))
g.FillRectangle(br, r);
break;
}
}
#endregion
#region SetStringAlignment
private void SetStringAlignment(StringFormat sf)
{
switch (_TextAlignment)
{
case TextAlignment.TopLeft:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.TopCenter:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.TopRight:
sf.LineAlignment = StringAlignment.Near;
sf.Alignment = StringAlignment.Far;
break;
case TextAlignment.MiddleLeft:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.MiddleCenter:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.MiddleRight:
sf.LineAlignment = StringAlignment.Center;
sf.Alignment = StringAlignment.Far;
break;
case TextAlignment.BottomLeft:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Near;
break;
case TextAlignment.BottomCenter:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Center;
break;
case TextAlignment.BottomRight:
sf.LineAlignment = StringAlignment.Far;
sf.Alignment = StringAlignment.Far;
break;
}
}
#endregion
#endregion
#region Contains
internal bool Contains(Point pt)
{
if (Angle == 0)
{
return (_Bounds.Contains(pt));
}
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(Bounds);
Matrix matrix = new Matrix();
matrix.RotateAt(_Angle, _Center);
path.Transform(matrix);
return (path.IsVisible(pt));
}
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeText copy = new GaugeText();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeText c = copy as GaugeText;
if (c != null)
{
base.CopyToItem(c);
c.Angle = _Angle;
c.AutoSize = _AutoSize;
if (_BackColor != null)
c.BackColor = (GradientFillColor)_BackColor.Clone();
if (_Font != null)
c.Font = (Font)_Font.Clone();
c.ForeColor = _ForeColor;
c.Location = _Location;
c.Size = _Size;
c.Text = _Text;
c.TextAlignment = _TextAlignment;
c.UnderScale = _UnderScale;
}
}
#endregion
}
#region Enums
public enum TextAlignment
{
TopLeft,
TopCenter,
TopRight,
MiddleLeft,
MiddleCenter,
MiddleRight,
BottomLeft,
BottomCenter,
BottomRight,
}
#endregion
}

View File

@@ -0,0 +1,472 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Globalization;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GradientFillColorConvertor))]
[Editor(typeof(GradientFillColorEditor), typeof(UITypeEditor))]
public class GradientFillColor : LinearGradientColorTable, ICloneable
{
#region Private properties
private int _BorderWidth;
private Color _BorderColor;
private GradientFillType _GradientFillType = GradientFillType.Auto;
#endregion
#region Constructors
/// <summary>
/// Creates new instance of the object.
/// </summary>
public GradientFillColor() { }
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color">Beginning color.</param>
public GradientFillColor(Color color)
{
Color1 = color;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Begin color.</param>
/// <param name="color2">End color.</param>
public GradientFillColor(Color color1, Color color2)
{
Color1 = color1;
Color2 = color2;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Beginning color in hexadecimal representation like FFFFFF.</param>
/// <param name="color2">End color in hexadecimal representation like FFFFFF.</param>
public GradientFillColor(string color1, string color2)
{
Color1 = ColorFactory.GetColor(color1);
Color2 = ColorFactory.GetColor(color2);
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Beginning color in 32-bit RGB representation.</param>
/// <param name="color2">End color in 32-bit RGB representation.</param>
public GradientFillColor(int color1, int color2)
{
Color1 = ColorFactory.GetColor(color1);
Color2 = ColorFactory.GetColor(color2);
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Beginning color in 32-bit RGB representation.</param>
/// <param name="color2">End color in 32-bit RGB representation.</param>
/// <param name="gradientAngle">Gradient angle.</param>
public GradientFillColor(int color1, int color2, int gradientAngle)
{
Color1 = ColorFactory.GetColor(color1);
Color2 = ColorFactory.GetColor(color2);
GradientAngle = gradientAngle;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Beginning color.</param>
/// <param name="color2">End color.</param>
/// <param name="gradientAngle">Gradient angle.</param>
public GradientFillColor(Color color1, Color color2, int gradientAngle)
{
Color1 = color1;
Color2 = color2;
GradientAngle = gradientAngle;
}
#endregion
#region Hidden properties
// ReSharper disable UnusedMember.Local
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Color Start
// ReSharper restore UnusedMember.Local
{
get { return (base.Start); }
set { base.Start = value; }
}
// ReSharper disable UnusedMember.Local
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Color End
// ReSharper restore UnusedMember.Local
{
get { return (base.End); }
set { base.End = value; }
}
#endregion
#region Public properties
#region Color1
/// <summary>
/// Gets or sets the beginning gradient Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the beginning gradient Color.")]
public Color Color1
{
get { return (base.Start); }
set { base.Start = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeColor1()
{
return (Color1.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetColor1()
{
Color1 = Color.Empty;
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal override bool ShouldSerializeStart()
{
return (false);
}
#endregion
#region Color2
/// <summary>
/// Gets or sets the ending gradient Color
/// </summary>
/// <returns></returns>
[Browsable(true), Category("Appearance")]
[Description("Indicates the ending gradient Color.")]
public Color Color2
{
get { return (base.End); }
set { base.End = value; }
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeColor2()
{
return (Color2.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetColor2()
{
Color2 = Color.Empty;
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal override bool ShouldSerializeEnd()
{
return (false);
}
#endregion
#region BorderColor
/// <summary>
/// Gets or sets the border Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the border Color.")]
public Color BorderColor
{
get { return (_BorderColor); }
set
{
if (_BorderColor != value)
{
_BorderColor = value;
OnColorTableChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeBorderColor()
{
return (_BorderColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetBorderColor()
{
BorderColor = Color.Empty;
}
#endregion
#region BorderWidth
/// <summary>
/// Gets or sets the border width
/// </summary>
[Browsable(true)]
[Category("Appearance"), DefaultValue(0)]
[Description("Indicates the border width.")]
public int BorderWidth
{
get { return (_BorderWidth); }
set
{
if (_BorderWidth != value)
{
_BorderWidth = value;
OnColorTableChanged();
}
}
}
#endregion
#region GradientFillType
/// <summary>
/// Gets or sets the Gradient FillType
/// </summary>
[Browsable(true)]
[Category("Appearance"), DefaultValue(GradientFillType.Auto)]
[Description("Indicates the Gradient FillType.")]
public GradientFillType GradientFillType
{
get { return (_GradientFillType); }
set
{
if (_GradientFillType != value)
{
_GradientFillType = value;
OnColorTableChanged();
}
}
}
#endregion
#endregion
#region IsEqualTo
/// <summary>
/// Determines if the fillcolor is equal to the given one
/// </summary>
/// <param name="fillColor">FillColor to compare</param>
/// <returns>true if equal</returns>
public bool IsEqualTo(GradientFillColor fillColor)
{
return (Color1 == fillColor.Color1 && Color2 == fillColor.Color2 &&
GradientAngle == fillColor.GradientAngle && GradientFillType == fillColor.GradientFillType &&
BorderColor == fillColor.BorderColor && BorderWidth == fillColor._BorderWidth);
}
/// <summary>
/// Determines if the fillcolor is equal to the given one
/// </summary>
/// <param name="begin"></param>
/// <param name="end"></param>
/// <param name="angle"></param>
/// <param name="gradientFill"></param>
/// <param name="borderColor"></param>
/// <param name="borderWidth"></param>
/// <returns></returns>
public bool IsEqualTo(Color begin, Color end, float angle,
GradientFillType gradientFill, Color borderColor, int borderWidth)
{
return (Color1 == begin && End == end &&
GradientAngle == angle && GradientFillType == gradientFill &&
borderColor == BorderColor && borderWidth == BorderWidth);
}
#endregion
#region ICloneable Members
public object Clone()
{
GradientFillColor fillColor = new GradientFillColor();
fillColor.Color1 = Color1;
fillColor.Color2 = Color2;
fillColor.BorderColor = BorderColor;
fillColor.BorderWidth = BorderWidth;
fillColor.GradientFillType = GradientFillType;
fillColor.GradientAngle = GradientAngle;
return (fillColor);
}
#endregion
}
#region Enums
public enum GradientFillType
{
Auto,
Angle,
Center,
HorizontalCenter,
None,
VerticalCenter,
StartToEnd,
}
#endregion
#region GradientFillColorConvertor
public class GradientFillColorConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GradientFillColor gc = value as GradientFillColor;
if (gc != null)
{
ColorConverter cvt = new ColorConverter();
string s = gc.Start.IsEmpty ? "(Empty)" : cvt.ConvertToString(gc.Start);
if (gc.End != Color.Empty)
s += ", " + cvt.ConvertToString(gc.End);
return (s);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
#region GradientFillColorEditor
public class GradientFillColorEditor : UITypeEditor
{
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (true);
}
#endregion
#region PaintValue
public override void PaintValue(PaintValueEventArgs e)
{
GradientFillColor fc = e.Value as GradientFillColor;
if (fc != null)
{
GradientFillType fillType = GetGradientFillType(fc);
switch (fillType)
{
case GradientFillType.None:
using (Brush br = new SolidBrush(fc.Start))
e.Graphics.FillRectangle(br, e.Bounds);
break;
case GradientFillType.Auto:
case GradientFillType.Angle:
using (Brush br = fc.GetBrush(e.Bounds))
e.Graphics.FillRectangle(br, e.Bounds);
break;
case GradientFillType.Center:
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(e.Bounds);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = fc.Start;
br.SurroundColors = new Color[] {fc.End};
e.Graphics.FillPath(br, path);
}
}
break;
case GradientFillType.HorizontalCenter:
Rectangle t1 = e.Bounds;
t1.Height /= 2;
using (LinearGradientBrush br = new LinearGradientBrush(t1, fc.End, fc.Color1, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
e.Graphics.FillRectangle(br, e.Bounds);
}
break;
case GradientFillType.StartToEnd:
using (Brush br = fc.GetBrush(e.Bounds, 0))
e.Graphics.FillRectangle(br, e.Bounds);
break;
case GradientFillType.VerticalCenter:
Rectangle t2 = e.Bounds;
t2.Width /= 2;
using (LinearGradientBrush br = new LinearGradientBrush(t2, fc.End, fc.Color1, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
e.Graphics.FillRectangle(br, e.Bounds);
}
break;
}
}
}
#endregion
#region GetGradientFillType
private GradientFillType GetGradientFillType(GradientFillColor fc)
{
return (fc.End.IsEmpty ? GradientFillType.None : fc.GradientFillType);
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,644 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugeBaseLabelConvertor))]
public class GaugeBaseLabel : GaugeItem
{
#region Private variables
private int _Radius;
private int _Offset;
private LabelLayout _Layout;
private GaugeScale _Scale;
#endregion
public GaugeBaseLabel()
{
_Layout = new LabelLayout();
HookEvents(true);
}
#region Hidden properties
#region Tooltip
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new string Tooltip
{
get { return (base.Tooltip); }
set { base.Tooltip = value; }
}
#endregion
#endregion
#region Public properties
#region Layout
/// <summary>
/// Gets the label Layout
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Contains the Label layout properties.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public LabelLayout Layout
{
get { return (_Layout); }
}
#endregion
#region Scale
/// <summary>
/// Gets the associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public virtual GaugeScale Scale
{
get { return (_Scale); }
internal set
{
_Scale = value;
OnGaugeItemChanged(true);
}
}
#endregion
#endregion
#region Internal properties
#region AbsFont
internal Font AbsFont
{
get
{
if (_Layout.AutoSize == false)
return (_Layout.Font);
if (_Layout.AbsFont == null)
{
if (Scale is GaugeCircularScale)
_Layout.AbsFont = GetAbsFont(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
_Layout.AbsFont = GetAbsFont(Scale as GaugeLinearScale);
}
return (_Layout.AbsFont);
}
set { _Layout.AbsFont = value; }
}
private Font GetAbsFont(GaugeCircularScale scale)
{
float emSize = _Layout.Font.SizeInPoints;
emSize = (emSize / 120) * scale.AbsRadius;
if (emSize <= 0)
emSize = 1;
return (new Font(_Layout.Font.FontFamily, emSize, _Layout.Font.Style));
}
private Font GetAbsFont(GaugeLinearScale scale)
{
float emSize = _Layout.Font.SizeInPoints;
emSize = (emSize / 120) * scale.AbsWidth;
return (new Font(_Layout.Font.FontFamily, emSize, _Layout.Font.Style));
}
#endregion
#region Offset
internal int Offset
{
get { return (_Offset); }
set { _Offset = value; }
}
#endregion
#region Radius
internal int Radius
{
get { return (_Radius); }
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
{
_Layout.LabelLayoutChanged += Layout_LabelLayoutChanged;
}
else
{
_Layout.LabelLayoutChanged -= Layout_LabelLayoutChanged;
}
}
#endregion
#region Event handling
void Layout_LabelLayoutChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcLabelMetrics();
AbsFont = null;
_Layout.AbsFont = null;
}
}
#region CalcLabelMetrics
private void CalcLabelMetrics()
{
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMetrics(Scale as GaugeLinearScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
_Radius = scale.AbsRadius;
if (_Radius > 0)
{
int offset = (int)(_Radius * _Layout.ScaleOffset);
switch (_Layout.Placement)
{
case DisplayPlacement.Near:
_Radius = scale.GetNearLabelRadius() - offset;
break;
case DisplayPlacement.Center:
_Radius += offset;
break;
case DisplayPlacement.Far:
_Radius = scale.GetFarLabelRadius() + offset;
break;
}
}
}
#endregion
#region CalcLinearMetrics
private void CalcLinearMetrics(GaugeLinearScale scale)
{
int width = scale.AbsWidth;
int offset = (int)(width * _Layout.ScaleOffset);
switch (_Layout.Placement)
{
case DisplayPlacement.Near:
_Offset = GetNearLabelOffset(scale) - offset;
break;
case DisplayPlacement.Center:
_Offset = scale.AbsScaleWidth / 2 - offset;
break;
case DisplayPlacement.Far:
_Offset = GetFarLabelOffset(scale) + offset;
break;
}
}
#region GetNearLabelOffset
private int GetNearLabelOffset(GaugeLinearScale scale)
{
int offset = 0;
if (scale.MajorTickMarks.Visible &&
scale.MajorTickMarks.Layout.Placement == DisplayPlacement.Near
&& scale.MajorTickMarks.Offset < offset)
{
offset = scale.MajorTickMarks.Offset;
}
if (scale.MinorTickMarks.Visible &&
scale.MinorTickMarks.Layout.Placement == DisplayPlacement.Near &&
scale.MinorTickMarks.Offset < offset)
{
offset = scale.MinorTickMarks.Offset;
}
return (offset);
}
#endregion
#region GetFarLabelOffset
private int GetFarLabelOffset(GaugeLinearScale scale)
{
int offset = scale.AbsScaleWidth;
if (scale.MajorTickMarks.Visible &&
scale.MajorTickMarks.Layout.Placement == DisplayPlacement.Far)
{
int n = scale.MajorTickMarks.Offset + scale.MajorTickMarks.Length;
if (n > offset)
offset = n;
}
if (scale.MinorTickMarks.Visible &&
scale.MinorTickMarks.Layout.Placement == DisplayPlacement.Far)
{
int n = scale.MinorTickMarks.Offset + scale.MinorTickMarks.Length;
if (n > offset)
offset = n;
}
return (offset);
}
#endregion
#endregion
#endregion
#endregion
#region PaintLabel
internal void PaintLabel(Graphics g,
string text, Brush br, LabelPoint lp, Font font)
{
if (Scale.Style == GaugeScaleStyle.Circular)
{
if (Layout.AdaptiveLabel == true)
{
PaintAdaptiveLabel(g, text, br, lp, font);
}
else
{
if (Layout.RotateLabel == true)
PaintRotatedLabel(g, text, br, lp, font);
else
PaintNonRotatedLabel(g, text, br, lp, font);
}
}
else
{
PaintRotatedLabel(g, text, br, lp, font);
}
}
#endregion
#region PaintRotatedLabel
internal void PaintRotatedLabel(Graphics g,
string text, Brush br, LabelPoint lp, Font font)
{
if (Scale is GaugeCircularScale)
PaintCircularRotatedLabel(g, text, br, lp, font);
else if (Scale is GaugeLinearScale)
PaintLinearRotatedLabel(g, text, br, lp, font, Scale as GaugeLinearScale);
}
#region PaintCircularRotatedLabel
private void PaintCircularRotatedLabel(
Graphics g, string text, Brush br, LabelPoint lp, Font font)
{
SizeF sz = g.MeasureString(text, font);
Size size = sz.ToSize();
float fontAngle = Layout.Angle;
if (Layout.AutoOrientLabel == true)
{
if (((fontAngle + lp.Angle) % 360) < 180)
fontAngle += 180;
}
g.TranslateTransform(lp.Point.X, lp.Point.Y);
g.RotateTransform((lp.Angle + 90) % 360);
g.TranslateTransform(0, GetRadiusDelta(size.Width, size.Height, fontAngle));
g.RotateTransform(fontAngle % 360);
g.DrawString(text, font, br,
new Point(-size.Width / 2, -size.Height / 2));
g.ResetTransform();
}
#endregion
#region PaintLinearRotatedLabel
private void PaintLinearRotatedLabel(Graphics g, string text,
Brush br, LabelPoint lp, Font font, GaugeLinearScale scale)
{
SizeF sz = g.MeasureString(text, font);
Size size = sz.ToSize();
float fontAngle = Layout.Angle;
g.TranslateTransform(lp.Point.X, lp.Point.Y);
if (scale.Orientation == Orientation.Horizontal)
g.TranslateTransform(0, -GetRadiusDelta(size.Width, size.Height, fontAngle));
else
g.TranslateTransform(-GetRadiusDelta(size.Height, size.Width, fontAngle), 0);
g.RotateTransform(fontAngle % 360);
g.DrawString(text, font, br,
new Point(-size.Width / 2, -size.Height / 2));
g.ResetTransform();
}
#endregion
#region GetRadiusDelta
private int GetRadiusDelta(int width, int height, float fontAngle)
{
if (Layout.Placement == DisplayPlacement.Center)
return (0);
float spd = (float)((width / 2) - (height / 2)) / 90;
float angle = fontAngle % 180;
int delta = (int)((height / 2) +
((angle > 90) ? (180 - angle) : angle) * spd) + 2;
return (Layout.Placement == DisplayPlacement.Near ? delta : - delta);
}
#endregion
#endregion
#region PaintNonRotatedLabel
internal void PaintNonRotatedLabel(Graphics g,
string text, Brush br, LabelPoint lp, Font font)
{
SizeF sz = g.MeasureString(text, font);
Size size = sz.ToSize();
float fontAngle = 360 - ((lp.Angle + Layout.Angle + 90) % 360);
g.TranslateTransform(lp.Point.X, lp.Point.Y);
g.RotateTransform((lp.Angle + 90) % 360);
g.TranslateTransform(0, GetRadiusDelta(size.Width, size.Height, fontAngle));
g.RotateTransform(fontAngle % 360);
g.DrawString(text, font, br,
new Point(-size.Width / 2, -size.Height / 2));
g.ResetTransform();
}
#endregion
#region PaintAdaptiveLabel
internal void PaintAdaptiveLabel(Graphics g,
string text, Brush br, LabelPoint lp, Font font)
{
SizeF tw = g.MeasureString(text, font);
if (Layout.Placement == DisplayPlacement.Near)
tw.Width += text.Length;
float c = (float)(Math.PI * _Radius * 2);
if (c > 0)
{
float radians = (float)GetRadians(lp.Angle);
float radOffset = (float)GetRadians((180 * tw.Width) / c);
float radCenter = radians;
radians -= radOffset;
bool flip = false;
if (_Layout.AutoOrientLabel == true)
{
flip = ((GetDegrees(radCenter) % 360) < 180);
if (flip == true)
radians += (radOffset * 2);
}
int n = (int)Math.Ceiling((double)text.Length / 32);
for (int i = 0; i < n; i++)
{
int len = Math.Min(text.Length - (i * 32), 32);
radians = PaintAdaptiveText(g,
text.Substring(i * 32, len), br, font, radians, flip);
}
}
}
#endregion
#region PaintAdaptiveText
private float PaintAdaptiveText(Graphics g,
string text, Brush br, Font font, float radians, bool flip)
{
CharacterRange[] crs = new CharacterRange[text.Length];
for (int j = 0; j < text.Length; j++)
crs[j] = new CharacterRange(j, 1);
using (StringFormat sf = new StringFormat())
{
sf.FormatFlags = StringFormatFlags.NoClip | StringFormatFlags.MeasureTrailingSpaces;
sf.SetMeasurableCharacterRanges(crs);
Rectangle r = new Rectangle(0, 0, 1000, 1000);
Region[] rgns = g.MeasureCharacterRanges(text, font, r, sf);
for (int j = 0; j < text.Length; j++)
{
RectangleF t = rgns[j].GetBounds(g);
float z = (flip ? _Radius - t.Height / 2 : _Radius + t.Height / 2);
switch (Layout.Placement)
{
case DisplayPlacement.Near:
t.Width += 1;
z -= t.Height/2;
break;
case DisplayPlacement.Far:
z += t.Height/2;
break;
}
float y = (float)(_Scale.Center.Y + z * Math.Sin(radians));
float x = (float)(_Scale.Center.X + z * Math.Cos(radians));
float rad = (float)Math.Asin(t.Width / (_Radius * 2));
radians += (flip ? -rad : rad);
g.TranslateTransform(x, y);
g.RotateTransform((flip ? -90 : 90) + (float)GetDegrees(radians));
g.DrawString(text[j].ToString(), font, br, 0, 0);
g.ResetTransform();
radians += (flip ? -rad : rad);
}
}
return (radians);
}
#endregion
#region GetDegrees
internal double GetDegrees(float radians)
{
return (radians * 180 / Math.PI);
}
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
internal double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region OnDispose
protected override void OnDispose()
{
HookEvents(false);
base.OnDispose();
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeBaseLabel copy = new GaugeBaseLabel();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeBaseLabel c = copy as GaugeBaseLabel;
if (c != null)
{
base.CopyToItem(c);
_Layout.CopyToItem(c.Layout);
}
}
#endregion
}
#region GaugeBaseLabelConvertor
public class GaugeBaseLabelConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeBaseLabel label = value as GaugeBaseLabel;
if (label != null)
return (String.Empty);
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,352 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
public class GaugeCustomLabelCollection : GenericCollection<GaugeCustomLabel>
{
#region ICloneable Members
public override object Clone()
{
GaugeCustomLabelCollection copy = new GaugeCustomLabelCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(GaugeCustomLabelCollection copy)
{
foreach (GaugeCustomLabel item in this)
{
GaugeCustomLabel ic = new GaugeCustomLabel();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
public class GaugeCustomLabel : GaugeBaseLabel
{
#region Private variables
private string _Text;
private double _Value;
private GaugeTickMarkLabel _TickMark;
private LabelPoint _LabelPoint;
#endregion
public GaugeCustomLabel()
{
_Text = "Text";
_Value = double.NaN;
_TickMark = new GaugeTickMarkLabel(
Scale, GaugeTickMarkRank.Custom, GaugeMarkerStyle.Trapezoid, .09f, .14f, double.NaN);
HookEvents(true);
}
#region Public properties
#region Scale
/// <summary>
/// Gets the label's associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override GaugeScale Scale
{
get { return (base.Scale); }
internal set
{
base.Scale = value;
_TickMark.Scale = value;
}
}
#endregion
#region Text
/// <summary>
/// Gets or sets the Label text
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue("Text")]
[Description("Indicates the Label text.")]
public string Text
{
get { return (_Text); }
set
{
if (value != null && value.Equals(_Text) == false)
{
_Text = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region TickMark
/// <summary>
/// Gets the Label Tickmark definition
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Contains the Label TickMark layout properties.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GaugeTickMarkLabel TickMark
{
get { return (_TickMark); }
}
#endregion
#region Value
/// <summary>
/// Gets or sets the Label scale value
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(double.NaN)]
[Description("Indicates the Label scale value.")]
public double Value
{
get { return (_Value); }
set
{
if (_Value != value)
{
_Value = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region NeedRecalcLayout
internal override bool NeedRecalcLayout
{
get { return (base.NeedRecalcLayout); }
set
{
base.NeedRecalcLayout = value;
if (value == true)
_TickMark.NeedRecalcLayout = true;
}
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
{
_TickMark.GaugeItemChanged += LabelTickMark_GaugeItemChanged;
}
else
{
_TickMark.GaugeItemChanged -= LabelTickMark_GaugeItemChanged;
}
}
#endregion
#region Event processing
void LabelTickMark_GaugeItemChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
if (_Value >= Scale.MinValue && _Value <= Scale.MaxValue)
{
if (Scale is GaugeCircularScale)
CalcCircularLabelPoint(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearLabelPoint(Scale as GaugeLinearScale);
_TickMark.Interval = _Value - Scale.MinValue;
_TickMark.NeedRecalcLayout = true;
_TickMark.RecalcLayout();
}
else
{
_LabelPoint = null;
_TickMark.TickPoint = null;
}
}
}
#region CalcCircularLabelPoint
private void CalcCircularLabelPoint(GaugeCircularScale scale)
{
double spread = scale.MaxValue - scale.MinValue;
double dpt = scale.SweepAngle / spread;
double interval = _Value - scale.MinValue;
double n = interval * dpt;
_LabelPoint = new LabelPoint();
_LabelPoint.Angle = (float)(scale.StartAngle + (scale.Reversed ? scale.SweepAngle - n : n));
_LabelPoint.Point = scale.GetPoint(Radius, _LabelPoint.Angle);
_LabelPoint.Interval = interval;
}
#endregion
#region CalcLinearLabelPoint
private void CalcLinearLabelPoint(GaugeLinearScale scale)
{
double ticks = scale.MaxValue - scale.MinValue;
_LabelPoint = new LabelPoint();
if (scale.Orientation == Orientation.Horizontal)
{
double dpt = scale.ScaleBounds.Width / ticks;
int dx = (int)((_Value - Scale.MinValue) * dpt);
int x = (scale.Reversed == true)
? Scale.Bounds.Right - dx : Scale.Bounds.X + dx;
_LabelPoint.Point = new Point(x, scale.ScaleBounds.Y + Offset);
}
else
{
double dpt = scale.ScaleBounds.Height / ticks;
int dy = (int)((_Value - Scale.MinValue) * dpt);
int y = (scale.Reversed == true)
? Scale.Bounds.Top + dy : Scale.Bounds.Bottom - dy;
_LabelPoint.Point = new Point(scale.ScaleBounds.X + Offset, y);
}
_LabelPoint.Interval = _Value;
}
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
RecalcLayout();
if (_LabelPoint != null)
{
if (_LabelPoint.Visible == true)
{
if (Scale.GaugeControl.OnPreRenderScaleCustomLabel(e, this) == false)
{
using (Brush br = new SolidBrush(Layout.ForeColor))
PaintLabel(g, _Text, br, _LabelPoint, AbsFont);
Scale.GaugeControl.OnPostRenderScaleCustomLabel(e, this);
}
}
}
}
#endregion
#region OnDispose
protected override void OnDispose()
{
HookEvents(false);
base.OnDispose();
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeCustomLabel copy = new GaugeCustomLabel();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeCustomLabel c = copy as GaugeCustomLabel;
if (c != null)
{
base.CopyToItem(c);
c.Text = _Text;
c.Value = _Value;
_TickMark.CopyToItem(c.TickMark);
}
}
#endregion
}
}

View File

@@ -0,0 +1,585 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugeLabelConvertor))]
public class GaugeIntervalLabel : GaugeBaseLabel
{
#region Private variables
private double _Interval;
private double _IntervalOffset;
private LabelPoint[] _LabelPoints;
private bool _ShowMaxLabel;
private bool _ShowMinLabel;
private string _FormatString;
#endregion
public GaugeIntervalLabel(GaugeScale scale)
{
Scale = scale;
_Interval = double.NaN;
_IntervalOffset = double.NaN;
_ShowMinLabel = true;
_ShowMaxLabel = true;
}
#region Hidden properties
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new string Name
{
get { return (base.Name); }
set { base.Name = value; }
}
#endregion
#region Public properties
#region FormatString
/// <summary>
/// Gets or sets the .Net format string used to display all non-custom defined labels.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the .Net format string used to display all non-custom defined labels.")]
[Editor("DevComponents.Instrumentation.Design.FormatStringEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
public string FormatString
{
get { return (_FormatString); }
set
{
if (_FormatString != value)
{
_FormatString = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Interval
/// <summary>
/// Gets or sets the Label Interval
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(double.NaN)]
[Description("Indicates the Label Interval.")]
public double Interval
{
get { return (_Interval); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_Interval != value)
{
_Interval = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region IntervalOffset
/// <summary>
/// Gets or sets the Label Interval Offset
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(double.NaN)]
[Description("Indicates the Label Interval Offset.")]
public double IntervalOffset
{
get { return (_IntervalOffset); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_IntervalOffset != value)
{
_IntervalOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region ShowMaxLabel
/// <summary>
/// Gets or sets whether to show the Maximum Scale label
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates whether to show the Maximum Scale label.")]
public bool ShowMaxLabel
{
get { return (_ShowMaxLabel); }
set
{
if (_ShowMaxLabel != value)
{
_ShowMaxLabel = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region ShowMinLabel
/// <summary>
/// Gets or sets whether to show the Minimum Scale label
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates whether to show the Minimum Scale label.")]
public bool ShowMinLabel
{
get { return (_ShowMinLabel); }
set
{
if (_ShowMinLabel != value)
{
_ShowMinLabel = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcLabelPoints();
}
}
#region CalcLabelPoints
private void CalcLabelPoints()
{
if (Scale is GaugeCircularScale)
CalcCircularLabelPoints(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearLabelPoints(Scale as GaugeLinearScale);
}
#region CalcCircularLabelPoints
private void CalcCircularLabelPoints(GaugeCircularScale scale)
{
double labelInterval = (_Interval.Equals(double.NaN) ?
scale.MajorTickMarks.Interval : _Interval);
double labelIntervalOffset = (_IntervalOffset.Equals(double.NaN) ?
scale.MajorTickMarks.IntervalOffset : _IntervalOffset);
double spread = scale.MaxValue - scale.MinValue;
double dpt = scale.SweepAngle / spread;
int n = GetPointCount(spread, labelInterval, labelIntervalOffset);
if (n > 0)
{
double startAngle = scale.StartAngle;
double interval = (_ShowMinLabel == true ? 0 : labelIntervalOffset > 0 ? labelIntervalOffset : labelInterval);
int dir = (scale.Reversed ? -1 : 1);
if (scale.Reversed == true)
startAngle += scale.SweepAngle;
_LabelPoints = new LabelPoint[n];
for (int i = 0; i < n; i++)
{
_LabelPoints[i] = new LabelPoint();
if (interval + scale.MinValue > scale.MaxValue)
interval = scale.MaxValue - scale.MinValue;
_LabelPoints[i].Angle = (float)(startAngle + (interval * dpt) * dir);
_LabelPoints[i].Point = scale.GetPoint(Radius, _LabelPoints[i].Angle);
_LabelPoints[i].Interval = interval;
if (interval >= labelIntervalOffset)
interval += labelInterval;
else
interval = labelIntervalOffset;
}
}
else
{
_LabelPoints = null;
}
}
#endregion
#region CalcLinearLabelPoints
private void CalcLinearLabelPoints(GaugeLinearScale scale)
{
double labelInterval = (_Interval.Equals(double.NaN) ?
scale.MajorTickMarks.Interval : _Interval);
double labelIntervalOffset = (_IntervalOffset.Equals(double.NaN) ?
scale.MajorTickMarks.IntervalOffset : _IntervalOffset);
double spread = Math.Abs(scale.MaxValue - scale.MinValue);
double dpt = scale.AbsScaleLength / spread;
int n = GetPointCount(spread, labelInterval, labelIntervalOffset);
if (n > 0)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalLabelPoints(scale, n, dpt, labelInterval, labelIntervalOffset);
else
CalcVerticalLabelPoints(scale, n, dpt, labelInterval, labelIntervalOffset);
}
else
{
_LabelPoints = null;
}
}
#region CalcHorizontalLabelPoints
private void CalcHorizontalLabelPoints(GaugeLinearScale scale,
int n, double dpt, double labelInterval, double labelIntervalOffset)
{
double interval = (_ShowMinLabel == true ?
0 : labelIntervalOffset > 0 ? labelIntervalOffset : labelInterval);
int y = scale.ScaleBounds.Y + Offset;
_LabelPoints = new LabelPoint[n];
for (int i = 0; i < n; i++)
{
_LabelPoints[i] = new LabelPoint();
if (interval + Scale.MinValue > Scale.MaxValue)
interval = Scale.MaxValue - Scale.MinValue;
int x = (scale.Reversed == true)
? (int)(Scale.Bounds.Right - dpt * interval)
: (int)(Scale.Bounds.X + dpt * interval);
_LabelPoints[i].Point = new Point(x, y);
_LabelPoints[i].Interval = interval;
if (interval >= labelIntervalOffset)
interval += labelInterval;
else
interval = labelIntervalOffset;
}
}
#endregion
#region CalcVerticalLabelPoints
private void CalcVerticalLabelPoints(GaugeLinearScale scale,
int n, double dpt, double labelInterval, double labelIntervalOffset)
{
double interval = (_ShowMinLabel == true ?
0 : labelIntervalOffset > 0 ? labelIntervalOffset : labelInterval);
int x = scale.ScaleBounds.X + Offset;
_LabelPoints = new LabelPoint[n];
for (int i = 0; i < n; i++)
{
_LabelPoints[i] = new LabelPoint();
if (interval + Scale.MinValue > Scale.MaxValue)
interval = Scale.MaxValue - Scale.MinValue;
int y = (scale.Reversed == true)
? (int)(Scale.Bounds.Top + dpt * interval)
: (int)(Scale.Bounds.Bottom - dpt * interval);
_LabelPoints[i].Point = new Point(x, y);
_LabelPoints[i].Interval = interval;
if (interval >= labelIntervalOffset)
interval += labelInterval;
else
interval = labelIntervalOffset;
}
}
#endregion
#endregion
#region GetPointCount
private int GetPointCount(double spread,
double labelInterval, double labelIntervalOffset)
{
int n = (int)Math.Ceiling((spread - labelIntervalOffset) / labelInterval) + 1;
if (labelIntervalOffset == 0)
{
if (_ShowMinLabel == false)
n--;
}
else
{
if (_ShowMinLabel == true)
n++;
}
if (_ShowMaxLabel == false)
n--;
return (n);
}
#endregion
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
RecalcLayout();
if (Scale.GaugeControl.OnPreRenderScaleTickMarkLabels(e, Scale) == false)
{
if (_LabelPoints != null)
{
Font font = AbsFont;
SolidBrush br = null;
try
{
foreach (LabelPoint lp in _LabelPoints)
{
if (CanDisplayLabel(lp) == true)
{
br = GetLabelBrush(br, lp);
PaintLabel(g, GetLabelText(lp), br, lp, font);
}
}
}
finally
{
if (br != null)
br.Dispose();
}
}
Scale.GaugeControl.OnPostRenderScaleTickMarkLabels(e, Scale);
}
}
#region GetLabelText
private string GetLabelText(LabelPoint labelPoint)
{
double n = Scale.GetIntervalValue(labelPoint.Interval);
if (String.IsNullOrEmpty(_FormatString) == false)
{
try
{
switch (_FormatString[0])
{
case 'X':
case 'x':
return (String.Format("{0:" + _FormatString + "}", (int) n));
default:
return (String.Format("{0:" + _FormatString + "}", n));
}
}
catch
{
}
}
return (n.ToString());
}
#endregion
#region GetLabelBrush
private SolidBrush GetLabelBrush(SolidBrush br, LabelPoint lp)
{
Color color = GetLabelColor(lp);
if (br == null || br.Color != color)
{
if (br != null)
br.Dispose();
br = new SolidBrush(color);
}
return (br);
}
#endregion
#region GetLabelColor
private Color GetLabelColor(LabelPoint lp)
{
Color labelColor = Scale.GetRangeLabelColor(lp.Interval);
if (labelColor.IsEmpty == true)
labelColor = Scale.GetSectionLabelColor(lp.Interval);
if (labelColor.IsEmpty == true)
labelColor = Layout.ForeColor;
return (labelColor);
}
#endregion
#region CanDisplayLabel
private bool CanDisplayLabel(LabelPoint labelPoint)
{
if (labelPoint.Visible == false)
return (false);
if (Scale.HasCustomLabels == true)
{
foreach (GaugeCustomLabel label in Scale.CustomLabels)
{
if (label.Visible == true)
{
if (label.Layout.Placement == Layout.Placement)
{
if (label.Value == Scale.MinValue + labelPoint.Interval)
return (false);
}
}
}
}
return (true);
}
#endregion
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeIntervalLabel copy = new GaugeIntervalLabel(Scale);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeIntervalLabel c = copy as GaugeIntervalLabel;
if (c != null)
{
base.CopyToItem(c);
c.FormatString = _FormatString;
c.Interval = _Interval;
c.IntervalOffset = _IntervalOffset;
c.ShowMaxLabel = _ShowMaxLabel;
c.ShowMinLabel = _ShowMinLabel;
}
}
#endregion
}
#region GaugeLabelConvertor
public class GaugeLabelConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeIntervalLabel label = value as GaugeIntervalLabel;
if (label != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,409 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(LabelLayoutConvertor))]
public class LabelLayout : IDisposable, ICloneable
{
#region Events
public event EventHandler<EventArgs> LabelLayoutChanged;
#endregion
#region Private variables
private DisplayPlacement _Placement;
private float _ScaleOffset;
private Font _Font;
private Font _AbsFont;
private float _Angle;
private bool _AutoSize;
private bool _RotateLabel;
private bool _AdaptiveLabel;
private bool _AutoOrientLabel;
private Color _ForeColor;
#endregion
public LabelLayout()
{
_ForeColor = Color.Black;
_Placement = DisplayPlacement.Near;
_AutoSize = true;
_AutoOrientLabel = true;
_RotateLabel = true;
}
#region Public properties
#region AdaptiveLabel
/// <summary>
/// Gets or sets whether labels are to adapt to the scale shape
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(false)]
[Description("Indicates whether labels are to adapt to the scale shape.")]
public bool AdaptiveLabel
{
get { return (_AdaptiveLabel); }
set
{
if (_AdaptiveLabel != value)
{
_AdaptiveLabel = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region Angle
/// <summary>
/// Gets or sets the additional number of degrees the label will be rotated
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(0f)]
[Description("Indicates the additional number of degrees the label will be rotated.")]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[NotifyParentProperty(true)]
public float Angle
{
get { return (_Angle); }
set
{
if (_Angle != value)
{
_Angle = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region AutoOrientLabel
/// <summary>
/// Gets or sets whether the label will be auto oriented away from being upside down
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(true)]
[Description("Indicates whether the label will be auto oriented away from being upside down.")]
public bool AutoOrientLabel
{
get { return (_AutoOrientLabel); }
set
{
if (_AutoOrientLabel != value)
{
_AutoOrientLabel = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region AutoSize
/// <summary>
/// Gets or sets whether the label Font size is auto sized
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(true)]
[Description("Indicates whether the label Font size is auto sized.")]
public bool AutoSize
{
get { return (_AutoSize); }
set
{
if (_AutoSize != value)
{
_AutoSize = value;
AbsFont = null;
OnLabelLayoutChanged();
}
}
}
#endregion
#region Font
/// <summary>
/// Gets or sets the Font to use for the label
/// </summary>
[Browsable(true)]
[Category("Appearance")]
[Description("Indicates the Font to use for the label.")]
public Font Font
{
get
{
if (_Font == null)
_Font = new Font("Microsoft SanSerif", 12);
return (_Font);
}
set
{
if (_Font != null)
_Font.Dispose();
_Font = value;
AbsFont = null;
OnLabelLayoutChanged();
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeFont()
{
if (_Font == null)
return (false);
using (Font font = new Font("Microsoft SanSerif", 12))
return (_Font.Equals(font) == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetFont()
{
Font = new Font("Microsoft SanSerif", 12);
}
#endregion
#region ForeColor
/// <summary>
/// Gets or sets the Label text Color
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(typeof(Color), "Black")]
[Description("Indicates the Label text Color.")]
public Color ForeColor
{
get { return (_ForeColor); }
set
{
if (_ForeColor != value)
{
_ForeColor = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region Placement
/// <summary>
/// Gets or sets the Placement of the Label with respect to the Scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(DisplayPlacement.Near)]
[Description("Indicates the Placement of the Label with respect to the Scale.")]
public DisplayPlacement Placement
{
get { return (_Placement); }
set
{
if (_Placement != value)
{
_Placement = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region RotateLabel
/// <summary>
/// Gets or sets whether labels are rotated along the scale
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(true)]
[Description("Indicates whether labels are rotated along the scale.")]
public bool RotateLabel
{
get { return (_RotateLabel); }
set
{
if (_RotateLabel != value)
{
_RotateLabel = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#region ScaleOffset
/// <summary>
/// Gets or sets the distance from the Label to the Scale, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the distance from the Label to the Scale, measured as a percentage.")]
public float ScaleOffset
{
get { return (_ScaleOffset); }
set
{
if (_ScaleOffset != value)
{
_ScaleOffset = value;
OnLabelLayoutChanged();
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsFont
internal Font AbsFont
{
get { return (_AbsFont); }
set
{
if (_AbsFont != null)
_AbsFont.Dispose();
_AbsFont = value;
}
}
#endregion
#endregion
#region OnLabelLayoutChanged
private void OnLabelLayoutChanged()
{
if (LabelLayoutChanged != null)
LabelLayoutChanged(this, EventArgs.Empty);
}
#endregion
#region IDisposable Members
public void Dispose()
{
Font = null;
AbsFont = null;
}
#endregion
#region ICloneable Members
public virtual object Clone()
{
LabelLayout copy = new LabelLayout();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal virtual void CopyToItem(LabelLayout copy)
{
copy.AdaptiveLabel = _AdaptiveLabel;
copy.Angle = _Angle;
copy.AutoOrientLabel = _AutoOrientLabel;
copy.AutoSize = _AutoSize;
if (_Font != null)
copy.Font = (Font)_Font.Clone();
copy.ForeColor = _ForeColor;
copy.Placement = _Placement;
copy.RotateLabel = _RotateLabel;
copy.ScaleOffset = _ScaleOffset;
}
#endregion
}
#region LabelLayoutConvertor
public class LabelLayoutConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
LabelLayout ll = value as LabelLayout;
if (ll != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,152 @@
using System.Drawing;
namespace DevComponents.Instrumentation
{
internal class LabelPoint
{
#region Private variables
private Point _Point;
private float _Angle;
private double _Interval;
private bool _Visible = true;
#endregion
#region Public properties
#region Angle
public float Angle
{
get { return (_Angle); }
set { _Angle = value; }
}
#endregion
#region Point
public Point Point
{
get { return (_Point); }
set { _Point = value; }
}
#endregion
#region Interval
public double Interval
{
get { return (_Interval); }
set { _Interval = value; }
}
#endregion
#region Visible
public bool Visible
{
get { return (_Visible); }
set { _Visible = value; }
}
#endregion
#endregion
#region PaintRotatedLabel
public void PaintRotatedLabel(Graphics g,
string text, LabelLayout layout, int height, Brush br, Font font)
{
SizeF sz = g.MeasureString(text, font);
Size size = sz.ToSize();
Point pt = new Point(0, 0);
switch (layout.Placement)
{
case DisplayPlacement.Far:
pt.Y = -height / 2;
break;
case DisplayPlacement.Near:
pt.Y = height / 2;
break;
}
g.TranslateTransform(_Point.X, _Point.Y);
g.RotateTransform((_Angle + 90) % 360);
g.TranslateTransform(pt.X, pt.Y);
float fontAngle = layout.Angle;
if (layout.AutoOrientLabel == true)
{
if (((_Angle + layout.Angle) % 360) < 180)
fontAngle += 180;
}
g.RotateTransform(fontAngle);
g.DrawString(text, font, br,
new Point(-size.Width / 2, -size.Height / 2));
g.ResetTransform();
}
#endregion
#region PaintNonRotatedLabel
public void PaintNonRotatedLabel(Graphics g, string text,
LabelLayout layout, Point center, int radius, Brush br, Font font)
{
SizeF sz = g.MeasureString(text, font);
int x = _Point.X - center.X;
int y = _Point.Y - center.Y;
Point pt = new Point();
switch (layout.Placement)
{
case DisplayPlacement.Far:
{
int dx = (int)(((float)(x - radius) / (radius * 2)) * sz.Width);
int dy = (int)(((float)(y - radius) / (radius * 2)) * sz.Height);
pt = new Point(_Point.X + dx, _Point.Y + dy);
}
break;
case DisplayPlacement.Near:
{
int dx = (int)(((float)(x + radius) / (radius * 2)) * sz.Width);
int dy = (int)(((float)(y + radius) / (radius * 2)) * sz.Height);
pt = new Point(_Point.X - dx, _Point.Y - dy);
}
break;
case DisplayPlacement.Center:
{
int dx = (int)(sz.Width / 2);
int dy = (int)(sz.Height / 2);
pt = new Point(_Point.X - dx, _Point.Y - dy);
}
break;
}
g.DrawString(text, font, br, pt);
}
#endregion
}
}

View File

@@ -0,0 +1,742 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugePinConvertor))]
public class GaugePin : GaugeItem
{
#region Private variables
private GaugeMarkerStyle _Style = GaugeMarkerStyle.Circle;
private DisplayPlacement _Placement = DisplayPlacement.Center;
private float _ScaleOffset; // Relative distance from scale
private float _EndOffset; // Relative distance or degrees from end
private GradientFillColor _FillColor;
private Image _Image;
private int _Radius;
private float _Angle;
private Rectangle _Bounds;
private float _Width;
private float _Length;
private bool _IsMaxPin;
private GaugeMarker _GaugeMarker;
private GaugePinLabel _Label;
private GaugeScale _Scale;
#endregion
public GaugePin(GaugeScale scale, bool isMmaxPin, string name)
{
_Scale = scale;
_IsMaxPin = isMmaxPin;
Name = name;
_GaugeMarker = new GaugeMarker();
_Label = new GaugePinLabel(this);
FillColor = new GradientFillColor(Color.WhiteSmoke);
FillColor.BorderColor = Color.DimGray;
FillColor.BorderWidth = 1;
Length = .06f;
Width = .06f;
_EndOffset = .02f;
HookEvents(true);
}
#region Public properties
#region EndOffset
/// <summary>
/// Gets or sets the offset from the end of the scale, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(.02f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the offset from the end of the scale, specified as a percentage.")]
public float EndOffset
{
get { return (_EndOffset); }
set
{
if (_EndOffset != value)
{
if (value < -1 || value > 1)
throw new ArgumentException("Value must be between -1 and +1.");
_EndOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region FillColor
/// <summary>
/// Gets or sets Indicates the Pin FillColor
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Pin FillColor.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor FillColor
{
get
{
if (_FillColor == null)
{
_FillColor = new GradientFillColor();
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
}
return (_FillColor);
}
set
{
if (_FillColor != null)
_FillColor.ColorTableChanged -= FillColor_ColorTableChanged;
_FillColor = value;
if (_FillColor != null)
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeFillColor()
{
return (FillColor.IsEqualTo(Color.WhiteSmoke,
Color.Empty, 90, GradientFillType.Auto, Color.DimGray, 1) == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetFillColor()
{
FillColor = new GradientFillColor(Color.WhiteSmoke);
FillColor.BorderColor = Color.DimGray;
FillColor.BorderWidth = 1;
}
#endregion
#region Image
/// <summary>
/// Gets or sets the Image to use for the Pin
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Image to use for the Pin.")]
public Image Image
{
get { return (_Image); }
set
{
if (_Image != value)
{
_Image = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region IsMaxPin
/// <summary>
/// Gets whether the pin is the Maximum Pin
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsMaxPin
{
get { return (_IsMaxPin); }
internal set { _IsMaxPin = value; }
}
#endregion
#region Label
/// <summary>
/// Gets or sets the Label associated with the Pin
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Label associated with the Pin.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GaugePinLabel Label
{
get { return (_Label); }
internal set { _Label = value; }
}
#endregion
#region Length
/// <summary>
/// Gets or sets the Length of the Pin, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(.06f)]
[Editor("DevComponents.Instrumentation.Design.RangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Length of the Pin, specified as a percentage.")]
public float Length
{
get { return (_Length); }
set
{
if (_Length != value)
{
if (value < 0 || value > 1)
throw new ArgumentException("Value must be between 0 and +1.");
_Length = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Placement
/// <summary>
/// Gets or sets the Placement of the Pin with respect to the Scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(DisplayPlacement.Center)]
[Description("Indicates the Placement of the Pin with respect to the Scale.")]
public DisplayPlacement Placement
{
get { return (_Placement); }
set
{
if (_Placement != value)
{
_Placement = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Scale
/// <summary>
/// Gets the pin's associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GaugeScale Scale
{
get { return (_Scale); }
internal set
{
_Scale = value;
_Label.Scale = value;
OnGaugeItemChanged(true);
}
}
#endregion
#region ScaleOffset
/// <summary>
/// Gets or sets the distance from the Pin to the Scale, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the distance from the Pin to the Scale, measured as a percentage.")]
public float ScaleOffset
{
get { return (_ScaleOffset); }
set
{
if (_ScaleOffset != value)
{
_ScaleOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Style
/// <summary>
/// Gets or sets the Pin display style
/// </summary>
[Browsable(true)]
[Category("Appearance"), DefaultValue(GaugeMarkerStyle.Circle)]
[Description("Indicates the Pin display style.")]
public GaugeMarkerStyle Style
{
get { return (_Style); }
set
{
if (_Style != value)
{
_Style = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Width
/// <summary>
/// Gets or sets the Width of the Pin, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(.06f)]
[Editor("DevComponents.Instrumentation.Design.WidthRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Width of the Pin, specified as a percentage.")]
public float Width
{
get { return (_Width); }
set
{
if (_Width != value)
{
if (value < 0 || value > 1)
throw new ArgumentException("Value must be between 0 and +1.");
_Width = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region Angle
internal float Angle
{
get { return (_Angle); }
}
#endregion
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
_Label.GaugeItemChanged += GaugePinLabel_GaugeItemChanged;
else
_Label.GaugeItemChanged -= GaugePinLabel_GaugeItemChanged;
}
#endregion
#region Event processing
void FillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
void GaugePinLabel_GaugeItemChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcPinMetrics();
_GaugeMarker.Clear();
_Label.NeedRecalcLayout = true;
}
}
#region CalcPinMetrics
private void CalcPinMetrics()
{
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMetrics(Scale as GaugeLinearScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
_Radius = scale.AbsRadius;
_Bounds = new Rectangle(0, 0, (int)(_Radius * _Width), (int)(_Radius * _Length));
int m = scale.AbsScaleWidth;
int offset = (int)(scale.AbsRadius * _ScaleOffset);
switch (_Placement)
{
case DisplayPlacement.Near:
_Radius -= ((_Bounds.Height + m) / 2 + offset);
break;
case DisplayPlacement.Center:
_Radius += (offset);
break;
case DisplayPlacement.Far:
_Radius += ((_Bounds.Height + m) / 2 + offset);
break;
}
float angle = _EndOffset * 360;
if (_IsMaxPin != scale.Reversed)
_Angle = scale.StartAngle + scale.SweepAngle + angle;
else
_Angle = scale.StartAngle - angle;
Point pt = scale.GetPoint(_Radius, _Angle);
_Bounds.Location = new Point(pt.X - _Bounds.Width / 2, pt.Y - _Bounds.Height / 2);
}
#endregion
#region CalcLinearMetrics
private void CalcLinearMetrics(GaugeLinearScale scale)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalMetrics(scale);
else
CalcVerticalMetrics(scale);
}
#region CalcHorizontalMetrics
private void CalcHorizontalMetrics(GaugeLinearScale scale)
{
int width = scale.AbsWidth;
int offset = (int)(width * _ScaleOffset);
int m = scale.AbsScaleWidth;
_Bounds = new Rectangle(0, 0, (int)(width * _Width), (int)(width * _Length));
int x = (int)(_EndOffset * scale.AbsLength);
if (_IsMaxPin != scale.Reversed)
x += scale.ScaleBounds.Right;
else
x = scale.ScaleBounds.Left - x;
x -= _Bounds.Width / 2;
int y = scale.ScaleBounds.Y;
switch (_Placement)
{
case DisplayPlacement.Near:
y -= (_Bounds.Height + offset);
break;
case DisplayPlacement.Center:
y -= ((_Bounds.Height - m) / 2 + offset);
break;
case DisplayPlacement.Far:
y += (m + offset);
break;
}
_Bounds.Location = new Point(x, y);
}
#endregion
#region CalcVerticalMetrics
private void CalcVerticalMetrics(GaugeLinearScale scale)
{
int width = scale.AbsWidth;
int offset = (int)(width * _ScaleOffset);
int m = scale.AbsScaleWidth;
_Bounds = new Rectangle(0, 0, (int)(width * _Width), (int)(width * _Length));
int y = (int)(_EndOffset * scale.AbsLength);
if (_IsMaxPin != scale.Reversed)
y = scale.ScaleBounds.Top - y;
else
y += scale.ScaleBounds.Bottom;
y -= _Bounds.Height / 2;
int x = scale.ScaleBounds.X;
switch (_Placement)
{
case DisplayPlacement.Near:
x -= (_Bounds.Width + offset);
break;
case DisplayPlacement.Center:
x -= ((_Bounds.Width - m ) / 2 + offset);
break;
case DisplayPlacement.Far:
x += (m + offset);
break;
}
_Bounds.Location = new Point(x, y);
}
#endregion
#endregion
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
RecalcLayout();
if (Scale.GaugeControl.OnPreRenderScaleGaugePin(e, this) == false)
{
Graphics g = e.Graphics;
if (_Bounds.Width > 0 && _Bounds.Height > 0)
{
Image image = _Image ?? GetPinBitmap(g);
if (image != null)
{
if (Scale is GaugeCircularScale)
PaintCircularPin(g, image);
else if (Scale is GaugeLinearScale)
PaintLinearPin(g, image);
}
if (_Label.Visible)
_Label.OnPaint(e);
}
Scale.GaugeControl.OnPostRenderScaleGaugePin(e, this);
}
}
#region PaintCircularPin
private void PaintCircularPin(Graphics g, Image image)
{
Rectangle r = new Rectangle(0, 0, _Bounds.Width, _Bounds.Height);
float angle = _Angle + 90;
if (_Placement == DisplayPlacement.Near)
angle += 180;
g.TranslateTransform(_Bounds.X + _Bounds.Width / 2, _Bounds.Y + _Bounds.Height / 2);
g.RotateTransform(angle % 360);
r.X -= _Bounds.Width / 2;
r.Y -= _Bounds.Height / 2;
g.DrawImage(image, r);
g.ResetTransform();
}
#endregion
#region PaintLinearPin
#region PaintLinearPin
private void PaintLinearPin(Graphics g, Image image)
{
g.DrawImage(image, _Bounds);
}
#endregion
#endregion
#region GetPinBitmap
internal Bitmap GetPinBitmap(Graphics g)
{
if (_Style != GaugeMarkerStyle.None)
return (_GaugeMarker.GetMarkerBitmap(g, _Style, _FillColor, _Bounds.Width, _Bounds.Height));
return (null);
}
#endregion
#endregion
#region OnDispose
protected override void OnDispose()
{
HookEvents(false);
_GaugeMarker.Dispose();
base.OnDispose();
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugePin copy = new
GaugePin(_Scale, _IsMaxPin, Name);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugePin c = copy as GaugePin;
if (c != null)
{
base.CopyToItem(c);
c.EndOffset = _EndOffset;
if (_FillColor != null)
c.FillColor = (GradientFillColor)_FillColor.Clone();
c.Image = _Image;
c.IsMaxPin = _IsMaxPin;
c.Length = _Length;
c.Placement = _Placement;
c.Scale = _Scale;
c.ScaleOffset = _ScaleOffset;
c.Style = _Style;
c.Width = _Width;
c.Label = new GaugePinLabel(c);
_Label.CopyToItem(c.Label);
}
}
#endregion
}
#region GaugePinConvertor
public class GaugePinConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugePin pin = value as GaugePin;
if (pin != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,183 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
public class GaugePinLabel : GaugeBaseLabel
{
#region Private variables
private string _Text;
private GaugePin _GaugePin;
private LabelPoint _LabelPoint;
#endregion
public GaugePinLabel(GaugePin gaugePin)
{
_Text = "";
_GaugePin = gaugePin;
Scale = gaugePin.Scale;
}
#region Public properties
#region Text
/// <summary>
/// Gets or sets the Label text
/// </summary>
[Browsable(true)]
[Category("Appearance"), DefaultValue("")]
[Description("Indicates the Label text.")]
public string Text
{
get { return (_Text); }
set
{
if (value != null && value.Equals(_Text) == false)
{
_Text = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region GaugePin
internal GaugePin GaugePin
{
get { return (_GaugePin); }
set
{
_GaugePin = value;
OnGaugeItemChanged(true);
}
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
_LabelPoint = null;
if (String.IsNullOrEmpty(_Text) == false)
{
if (Scale is GaugeCircularScale)
CalcCircularLabelPoint(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearLabelPoint(Scale as GaugeLinearScale);
}
}
}
#region CalcCircularLabelPoint
private void CalcCircularLabelPoint(GaugeCircularScale scale)
{
if (Radius > 0)
{
_LabelPoint = new LabelPoint();
_LabelPoint.Angle = _GaugePin.Angle;
_LabelPoint.Point = scale.GetPoint(Radius, _LabelPoint.Angle);
}
}
#endregion
#region CalcLinearLabelPoint
private void CalcLinearLabelPoint(GaugeLinearScale scale)
{
_LabelPoint = new LabelPoint();
if (scale.Orientation == Orientation.Horizontal)
{
_LabelPoint.Point = new Point(
_GaugePin.Bounds.X + _GaugePin.Bounds.Width / 2,
scale.ScaleBounds.Y + Offset);
}
else
{
_LabelPoint.Point = new Point(
scale.ScaleBounds.X + Offset,
_GaugePin.Bounds.Y + _GaugePin.Bounds.Height / 2);
}
}
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
RecalcLayout();
if (_LabelPoint != null && _LabelPoint.Visible == true)
{
using (Brush br = new SolidBrush(Layout.ForeColor))
PaintLabel(g, _Text, br, _LabelPoint, AbsFont);
}
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugePinLabel copy = new GaugePinLabel(_GaugePin);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugePinLabel c = copy as GaugePinLabel;
if (c != null)
{
base.CopyToItem(c);
c.Text = _Text;
}
}
#endregion
}
}

View File

@@ -0,0 +1,784 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeBarRenderer : GaugePointerRenderer
{
#region Private variables
private float _StartAngle;
private float _SweepAngle;
private float _RoundAngle;
private double _Marker;
private double _Origin;
private Rectangle _Bounds;
#endregion
internal GaugeBarRenderer(GaugePointer gaugePointer)
: base(gaugePointer)
{
}
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region Marker
internal double Marker
{
get { return (_Marker); }
}
#endregion
#region Origin
internal double Origin
{
get { return (_Origin); }
}
#endregion
#region RoundAngle
internal float RoundAngle
{
get { return (_RoundAngle); }
set { _RoundAngle = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
if (Scale is GaugeCircularScale)
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMarkerPoint(Scale as GaugeLinearScale);
}
#region CalcCircularMarkerPoint
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
{
int radius = Radius;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
radius -= (Width / 2);
break;
case DisplayPlacement.Far:
radius += (Width / 2);
break;
}
_Bounds.Size = new Size(radius * 2, radius * 2);
_Bounds.Location = new Point(scale.Center.X - radius, scale.Center.Y - radius);
Dpt = scale.SweepAngle / scale.Spread;
_Origin = GetOriginInterval() - scale.MinValue;
_Marker = GetInterval(Value) - scale.MinValue;
if (scale.Reversed == true)
{
IntervalAngle = (float)(scale.StartAngle + scale.SweepAngle - (_Marker * Dpt));
_StartAngle = (float)(scale.StartAngle + scale.SweepAngle - (_Origin * Dpt));
}
else
{
IntervalAngle = (float)(scale.StartAngle + _Marker * Dpt);
_StartAngle = (float)(scale.StartAngle + _Origin * Dpt);
}
IntervalPoint = scale.GetPoint(radius, IntervalAngle);
_SweepAngle = IntervalAngle - _StartAngle;
if (GaugePointer.BarStyle != BarPointerStyle.Square)
{
_RoundAngle = 0;
if (_SweepAngle != 0)
{
float x = (float)((360 * Width / 2) / (radius * 2 * Math.PI));
_RoundAngle = (_SweepAngle > 0)
? Math.Min(x, _SweepAngle) : Math.Max(-x, _SweepAngle);
_SweepAngle -= _RoundAngle;
}
}
}
#endregion
#region CalcLinearMarkerPoint
protected virtual void CalcLinearMarkerPoint(GaugeLinearScale scale)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalMarkerPoint(scale);
else
CalcVerticalMarkerPoint(scale);
}
#region CalcHorizontalMarkerPoint
protected virtual void CalcHorizontalMarkerPoint(GaugeLinearScale scale)
{
int offset = GaugePointer.Offset;
int y = scale.ScaleBounds.Y + scale.ScaleBounds.Height / 2 + offset;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
y -= Width;
break;
case DisplayPlacement.Center:
y -= (Width / 2);
break;
case DisplayPlacement.Far:
break;
}
Dpt = scale.ScaleBounds.Width / scale.Spread;
_Origin = GetOriginInterval() - scale.MinValue;
_Marker = GetInterval(Value) - scale.MinValue;
CalcHorizontalMarkerBounds(scale, y);
}
#region CalcHorizontalMarkerBounds
protected virtual void CalcHorizontalMarkerBounds(GaugeLinearScale scale, int y)
{
double origin = _Origin;
double marker = _Marker;
_RoundAngle = 0;
if (marker < origin)
{
_RoundAngle += 180;
SwapDoubles(ref marker, ref origin);
}
int len = (int)((marker - origin) * Dpt);
int x = (scale.Reversed == true)
? scale.ScaleBounds.Right - (int)(origin * Dpt) - len
: scale.ScaleBounds.X + (int)(origin * Dpt);
_Bounds = new Rectangle(0, 0, len, Width);
_Bounds.Location = new Point(x, y);
}
#endregion
#endregion
#region CalcVerticalMarkerPoint
protected virtual void CalcVerticalMarkerPoint(GaugeLinearScale scale)
{
int offset = GaugePointer.Offset;
int x = scale.ScaleBounds.X + scale.ScaleBounds.Width / 2 + offset;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
x -= Width;
break;
case DisplayPlacement.Center:
x -= (Width / 2);
break;
case DisplayPlacement.Far:
break;
}
Dpt = scale.ScaleBounds.Height / scale.Spread;
_Origin = GetOriginInterval() - scale.MinValue;
_Marker = GetInterval(Value) - scale.MinValue;
CalcVerticalMarkerBounds(scale, x);
}
#region CalcVerticalMarkerBounds
protected virtual void CalcVerticalMarkerBounds(GaugeLinearScale scale, int x)
{
double origin = _Origin;
double marker = _Marker;
_RoundAngle = -90;
if (marker < origin)
{
_RoundAngle += 180;
SwapDoubles(ref marker, ref origin);
}
int len = (int)((marker - origin) * Dpt);
int y = (scale.Reversed == true)
? scale.ScaleBounds.Top + (int)(marker * Dpt) - len
: scale.ScaleBounds.Bottom - (int)(marker * Dpt);
_Bounds = new Rectangle(0, 0, Width, len);
_Bounds.Location = new Point(x, y);
}
#endregion
#endregion
#endregion
#region GetOriginInterval
private double GetOriginInterval()
{
switch (GaugePointer.Origin)
{
case PointerOrigin.Minimum:
return (GetInterval(double.MinValue));
case PointerOrigin.Maximum:
return (GetInterval(double.MaxValue));
default:
return (GetInterval(GaugePointer.OriginInterval));
}
}
#endregion
#endregion
#region RenderCircular
public override void RenderCircular(PaintEventArgs e)
{
Graphics g = e.Graphics;
GaugeCircularScale scale = Scale as GaugeCircularScale;
if (scale != null)
{
if (Width > 0 && Radius > 0 && (_SweepAngle != 0 || _RoundAngle != 0))
{
using (GraphicsPath path = GetCircularBarPath(scale))
RenderBar(g, path);
}
}
}
#region GetCircularBarPath
private GraphicsPath GetCircularBarPath(GaugeCircularScale scale)
{
GraphicsPath path = new GraphicsPath();
Rectangle r = _Bounds;
r.Inflate(Width / 2, Width / 2);
path.AddArc(r, _StartAngle, _SweepAngle);
if (_RoundAngle != 0)
{
if (GaugePointer.BarStyle != BarPointerStyle.Square)
{
Point pt = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle);
Point pt2 = scale.GetPoint(_Bounds.Width/2, _StartAngle + _SweepAngle + _RoundAngle);
int dx = pt2.X - pt.X;
int dy = pt2.Y - pt.Y;
double n = Math.Max(1, Math.Sqrt((dx * dx) + (dy * dy)));
float angle = (_StartAngle + _SweepAngle) % 360;
using (GraphicsPath path2 = new GraphicsPath())
{
Matrix matrix = new Matrix();
matrix.RotateAt(angle, pt);
r.X = pt.X - Width/2 + 1;
r.Y = pt.Y - (int) n;
r.Width = Width - 1;
r.Height = (int) (n*2);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path2.AddArc(r, 0, _SweepAngle + _RoundAngle > 0 ? 180 : -180);
}
else
{
path2.AddLine(new Point(r.Right, r.Y + r.Height/2),
new Point(r.X + Width/2, _SweepAngle + _RoundAngle > 0 ? r.Bottom : r.Y));
}
path2.Transform(matrix);
path.AddPath(path2, true);
}
}
}
r = _Bounds;
r.Inflate(-Width / 2, -Width / 2);
path.AddArc(r, _StartAngle + _SweepAngle, -_SweepAngle);
path.CloseFigure();
return (path);
}
#endregion
#endregion
#region RenderLinear
public override void RenderLinear(PaintEventArgs e)
{
Graphics g = e.Graphics;
GaugeLinearScale scale = Scale as GaugeLinearScale;
if (scale != null)
{
if (_Bounds.Width > 0 && _Bounds.Height > 0)
{
using (GraphicsPath path = GetLinearBarPath(scale, _Bounds))
RenderBar(g, path);
}
}
}
#region GetLinearBarPath
private GraphicsPath GetLinearBarPath(GaugeLinearScale scale, Rectangle b)
{
GraphicsPath path = new GraphicsPath();
if (GaugePointer.BarStyle == BarPointerStyle.Square)
{
path.AddRectangle(b);
}
else
{
return ((scale.Orientation == Orientation.Horizontal)
? GetHorizontalBarPath(path, b)
: GetVerticalBarPath(path, b));
}
return (path);
}
#endregion
#region GetHorizontalBarPath
private GraphicsPath GetHorizontalBarPath(GraphicsPath path, Rectangle b)
{
if (_Marker < _Origin != Scale.Reversed)
{
int x = Math.Min(b.X + Width / 2, b.Right);
Point[] pts = new Point[] {
new Point(x, b.Y),
new Point (b.Right, b.Y),
new Point (b.Right, b.Bottom),
new Point (x, b.Bottom)};
path.AddLines(pts);
Rectangle r = new Rectangle(b.X, b.Y, (x - b.X) * 2, Width);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 90, 180);
}
else
{
path.AddLine(new Point(r.X + r.Width/2, r.Bottom),
new Point(r.X, r.Y + r.Height/2));
}
path.CloseAllFigures();
}
else
{
int x = Math.Max(b.Right - Width / 2, b.X);
Point[] pts = new Point[] {
new Point(x, b.Bottom),
new Point (b.X, b.Bottom),
new Point (b.X, b.Y),
new Point (x, b.Y)};
path.AddLines(pts);
int n = b.Right - x;
Rectangle r = new Rectangle(x - n, b.Y, n * 2, Width);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 270, 180);
}
else
{
path.AddLine(new Point(r.X + r.Width / 2, r.Y),
new Point(r.Right, r.Y + r.Height / 2));
}
path.CloseAllFigures();
}
return (path);
}
#endregion
#region GetVerticalBarPath
private GraphicsPath GetVerticalBarPath(GraphicsPath path, Rectangle b)
{
if (_Marker < _Origin != Scale.Reversed)
{
int y = Math.Max(b.Bottom - Width / 2, b.Y);
Point[] pts = new Point[] {
new Point(b.X, y),
new Point (b.X, b.Y),
new Point (b.Right, b.Y),
new Point (b.Right, y)};
path.AddLines(pts);
int n = b.Bottom - y;
Rectangle r = new Rectangle(b.X, y - n, Width, n * 2);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 0, 180);
}
else
{
path.AddLine(new Point(r.Right, r.Y + r.Height / 2),
new Point(r.X + r.Width / 2, r.Bottom ));
}
}
else
{
int y = Math.Min(b.Y + Width / 2, b.Bottom);
Point[] pts = new Point[] {
new Point(b.Right, y),
new Point (b.Right, b.Bottom),
new Point (b.X, b.Bottom),
new Point (b.X, y)};
path.AddLines(pts);
Rectangle r = new Rectangle(b.X, b.Y, Width, (y - b.Y) * 2);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 180, 180);
}
else
{
path.AddLine(new Point(r.X, r.Y + r.Height / 2),
new Point(r.X + r.Width / 2, r.Y));
}
}
path.CloseAllFigures();
return (path);
}
#endregion
#endregion
#region RenderBar
#region RenderBar
protected void RenderBar(Graphics g, GraphicsPath path)
{
RenderBar(g, path, GetPointerFillColor(GaugePointer.Value));
}
protected void RenderBar(Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
if (fillColor.End.IsEmpty == true || fillColor.Color1 == fillColor.Color2 ||
fillColor.GradientFillType == GradientFillType.None)
{
using (Brush br = new SolidBrush(fillColor.Color1))
g.FillPath(br, path);
}
else
{
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
? GradientFillType.Center
: fillColor.GradientFillType;
switch (fillType)
{
case GradientFillType.Auto:
case GradientFillType.StartToEnd:
RenderBarStartToEnd(g, path, fillColor);
break;
case GradientFillType.Angle:
RenderBarByAngle(g, path, fillColor);
break;
case GradientFillType.Center:
RenderBarByCenter(g, path, fillColor);
break;
case GradientFillType.HorizontalCenter:
RenderBarByHc(g, path, fillColor);
break;
case GradientFillType.VerticalCenter:
RenderBarByVc(g, path, fillColor);
break;
}
}
if (fillColor.BorderWidth > 0)
{
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
g.DrawPath(pen, path);
}
}
#endregion
#region RenderBarStartToEnd
private void RenderBarStartToEnd(Graphics g,
GraphicsPath path, GradientFillColor fillColor)
{
if (Scale is GaugeCircularScale)
{
using (PathGradientBrush br = ((GaugeCircularScale)Scale).CreateGradient(
Scale.GaugeControl.Frame.Bounds, _StartAngle, _SweepAngle, fillColor, Width * 2))
{
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
using (Brush br2 = new SolidBrush(fillColor.Color2))
g.FillPath(br2, path);
}
g.FillPath(br, path);
}
}
else
{
Rectangle t = Rectangle.Round(path.GetBounds());
float angle = _RoundAngle + (Scale.Reversed ? 180 : 0);
using (Brush br = fillColor.GetBrush(t, (int)angle))
g.FillPath(br, path);
}
}
#endregion
#region RenderBarByAngle
private void RenderBarByAngle(Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
int n = Width / 2;
Rectangle t = Rectangle.Round(path.GetBounds());
t.Inflate(n, n);
using (Brush br = fillColor.GetBrush(t))
g.FillPath(br, path);
}
#endregion
#region RenderBarByCenter
protected virtual void RenderBarByCenter(Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.WrapMode = WrapMode.TileFlipXY;
br.CenterColor = fillColor.Color1;
br.SurroundColors = new Color[] {fillColor.Color2};
if (Scale is GaugeCircularScale)
{
br.CenterPoint = Scale.Center;
float m = (float)Width / (_Bounds.Width / 2);
Blend blnd = new Blend();
blnd.Positions = new float[] { 0f, m, 1f };
blnd.Factors = new float[] { 1f, 0f, 0f };
br.Blend = blnd;
}
g.FillPath(br, path);
}
}
#endregion
#region RenderBarByHc
private void RenderBarByHc(Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
Rectangle t = Rectangle.Round(path.GetBounds());
t.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, fillColor.Color1, fillColor.Color2, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
}
#endregion
#region RenderBarByVc
private void RenderBarByVc(Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
Rectangle t = Rectangle.Round(path.GetBounds());
t.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, fillColor.Color1, fillColor.Color2, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
}
#endregion
#endregion
#region GetPointerPath
public override GraphicsPath GetPointerPath()
{
if (PointerPath == null)
{
if (Width > 0)
{
PointerPath = Scale.GaugeControl.OnGetPointerPath(GaugePointer, Scale.Bounds);
if (PointerPath == null)
{
if (Scale is GaugeCircularScale)
GetCPointerPath(Scale as GaugeCircularScale);
else
GetLPointerPath(Scale as GaugeLinearScale);
}
}
}
return (PointerPath);
}
#endregion
#region GetCPointerPath
private void GetCPointerPath(GaugeCircularScale scale)
{
if (Radius > 0 && (_SweepAngle != 0 || _RoundAngle != 0))
PointerPath = GetCircularBarPath(scale);
}
#endregion
#region GetLPointerPath
private void GetLPointerPath(GaugeLinearScale scale)
{
if (_Bounds.Width > 0 && _Bounds.Height > 0)
PointerPath = GetLinearBarPath(scale, _Bounds);
}
#endregion
#region OnMouseDown
internal override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
GaugePointer.ValueEx = GetValueFromPoint(e.Location);
}
#endregion
}
#region Enums
public enum BarPointerStyle
{
Square,
Rounded,
Pointed
}
#endregion
}

View File

@@ -0,0 +1,417 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeMarkerRenderer : GaugePointerRenderer, IDisposable
{
#region Private variables
private int _LastWidth;
private int _LastLength;
private GaugeMarkerStyle _LastMarkerStyle;
private Rectangle _Bounds;
private GaugeMarker _GaugeMarker;
#endregion
internal GaugeMarkerRenderer(GaugePointer gaugePointer)
: base(gaugePointer)
{
_GaugeMarker = new GaugeMarker();
}
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
if (Scale is GaugeCircularScale)
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMarkerPoint(Scale as GaugeLinearScale);
if ((Width != _LastWidth || Length != _LastLength) ||
(GaugePointer.MarkerStyle != _LastMarkerStyle))
{
_GaugeMarker.Clear();
_LastWidth = Width;
_LastLength = Length;
_LastMarkerStyle = GaugePointer.MarkerStyle;
}
}
#region CalcCircularMarkerPoint
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
{
int radius = Radius;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
radius -= Length;
break;
case DisplayPlacement.Center:
radius += (Length / 2);
break;
case DisplayPlacement.Far:
radius += Length;
break;
}
Dpt = scale.SweepAngle / scale.Spread;
double marker = GetInterval(Value) - scale.MinValue;
IntervalAngle = (float)(scale.Reversed
? scale.StartAngle + scale.SweepAngle - (marker * Dpt)
: scale.StartAngle + (marker * Dpt));
IntervalPoint = scale.GetPoint(radius, IntervalAngle);
}
#endregion
#region CalcLinearMarkerPoint
private void CalcLinearMarkerPoint(GaugeLinearScale scale)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalMarkerPoint(scale);
else
CalcVerticalMarkerPoint(scale);
}
#region CalcHorizontalMarkerPoint
private void CalcHorizontalMarkerPoint(GaugeLinearScale scale)
{
int offset = GaugePointer.Offset;
_Bounds = new Rectangle(0, 0, Width, Length);
int y = scale.ScaleBounds.Y + scale.ScaleBounds.Height / 2 + offset;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
y -= Length;
break;
case DisplayPlacement.Center:
y -= (Length / 2);
break;
case DisplayPlacement.Far:
break;
}
Dpt = scale.ScaleBounds.Width / scale.Spread;
double marker = GetInterval(Value) - scale.MinValue;
int n = _Bounds.Width / 2;
int x = (scale.Reversed == true)
? scale.ScaleBounds.Right - (int)(marker * Dpt) - n
: scale.ScaleBounds.X + (int)(marker * Dpt) - n;
_Bounds.Location = new Point(x, y);
IntervalPoint = new Point(_Bounds.X + n, _Bounds.Y + _Bounds.Height / 2);
}
#endregion
#region CalcVerticalMarkerPoint
private void CalcVerticalMarkerPoint(GaugeLinearScale scale)
{
int offset = GaugePointer.Offset;
_Bounds = new Rectangle(0, 0, Width, Length);
int x = scale.ScaleBounds.X + scale.ScaleBounds.Width / 2 + offset;
switch (GaugePointer.Placement)
{
case DisplayPlacement.Near:
x -= Width;
break;
case DisplayPlacement.Center:
x -= (Width / 2);
break;
case DisplayPlacement.Far:
break;
}
Dpt = scale.ScaleBounds.Height / scale.Spread;
double marker = GetInterval(Value) - scale.MinValue;
int n = _Bounds.Height / 2;
int y = (scale.Reversed == true)
? scale.ScaleBounds.Top + (int)(marker * Dpt) - n
: scale.ScaleBounds.Bottom - (int)(marker * Dpt) - n;
_Bounds.Location = new Point(x, y);
IntervalPoint = new Point(_Bounds.X + _Bounds.Width / 2, _Bounds.Y + n);
}
#endregion
#endregion
#endregion
#region RenderCircular
public override void RenderCircular(PaintEventArgs e)
{
if (IntervalPoint.IsEmpty == false &&
(Width > 0 && Length > 0 && Radius > 0))
{
Graphics g = e.Graphics;
Rectangle r = new Rectangle(0, 0, Width, Length);
r.X -= Width / 2;
float angle = IntervalAngle + 90;
if (GaugePointer.Placement == DisplayPlacement.Near)
angle += 180;
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
g.RotateTransform(angle % 360);
if (GaugePointer.Image != null)
{
g.DrawImage(GaugePointer.Image, r);
}
else
{
GraphicsPath path = GetMarkerPath(r);
if (path != null)
{
GradientFillColor fillColor =
GetPointerFillColor(GaugePointer.Value);
_GaugeMarker.FillMarkerPath(g, path, r, MarkerStyle, fillColor);
}
}
g.ResetTransform();
}
}
#endregion
#region RenderLinear
public override void RenderLinear(PaintEventArgs e)
{
if (_Bounds.Width > 0 && _Bounds.Height > 0)
{
Graphics g = e.Graphics;
Rectangle r = new Rectangle(0, 0, Width, Length);
r.X -= Width / 2;
r.Y -= Length / 2;
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
if (((GaugeLinearScale)Scale).Orientation == Orientation.Horizontal)
{
if (GaugePointer.Placement == DisplayPlacement.Far)
g.RotateTransform(180);
}
else
{
int angle = (GaugePointer.Placement == DisplayPlacement.Far) ? 90 : -90;
g.RotateTransform(angle);
}
if (GaugePointer.Image != null)
{
g.DrawImage(GaugePointer.Image, r);
}
else
{
GraphicsPath path = GetMarkerPath(r);
if (path != null)
{
GradientFillColor fillColor =
GetPointerFillColor(GaugePointer.Value);
_GaugeMarker.FillMarkerPath(g, path, r, MarkerStyle, fillColor);
}
}
g.ResetTransform();
}
}
#endregion
#region GetPointerPath
public override GraphicsPath GetPointerPath()
{
if (PointerPath == null)
{
if (MarkerStyle != GaugeMarkerStyle.None)
{
if (Width > 0 && Length > 0)
{
if (Scale is GaugeCircularScale)
GetCPointerPath();
else
GetLPointerPath();
}
}
}
return (PointerPath);
}
#region GetCPointerPath
private void GetCPointerPath()
{
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
r.X -= Width / 2;
PointerPath = GetMarkerPath(r);
if (PointerPath != null)
{
float angle = IntervalAngle + 90;
if (GaugePointer.Placement == DisplayPlacement.Near)
angle += 180;
Matrix matrix = new Matrix();
matrix.RotateAt(angle % 360, IntervalPoint);
PointerPath.Transform(matrix);
}
}
#endregion
#region GetLPointerPath
private void GetLPointerPath()
{
if (((GaugeLinearScale)Scale).Orientation == Orientation.Horizontal)
GetLhPointerPath();
else
GetLvPointerPath();
}
#region GetLhPointerPath
private void GetLhPointerPath()
{
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
r.X -= Width / 2;
r.Y -= Length / 2;
PointerPath = GetMarkerPath(r);
if (GaugePointer.Placement == DisplayPlacement.Far)
{
Matrix matrix = new Matrix();
matrix.RotateAt(180, IntervalPoint);
PointerPath.Transform(matrix);
}
}
#endregion
#region GetLvPointerPath
private void GetLvPointerPath()
{
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, Length);
r.X -= Width / 2;
r.Y -= Length / 2;
PointerPath = GetMarkerPath(r);
int angle = (GaugePointer.Placement == DisplayPlacement.Far) ? 90 : -90;
Matrix matrix = new Matrix();
matrix.RotateAt(angle, IntervalPoint);
PointerPath.Transform(matrix);
}
#endregion
#endregion
#region GetMarkerPath
private GraphicsPath GetMarkerPath(Rectangle r)
{
GraphicsPath path = GaugePointer.Scale.GaugeControl.OnGetPointerPath(GaugePointer, r);
if (path == null)
path = _GaugeMarker.GetMarkerPath(MarkerStyle, r);
else
PointerPath = null;
return (path);
}
#endregion
#endregion
#region IDisposable Members
public void Dispose()
{
PointerPath = null;
_GaugeMarker.Dispose();
}
#endregion
}
}

View File

@@ -0,0 +1,707 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeNeedleRenderer : GaugePointerRenderer, IDisposable
{
#region Private variables
private int _CapWidth;
private Rectangle _CapBounds;
#endregion
internal GaugeNeedleRenderer(GaugePointer gaugePointer)
: base(gaugePointer)
{
}
#region Public properties
#region CapBounds
public Rectangle CapBounds
{
get { return (_CapBounds); }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
CalcMarkerPoint();
}
#region CalcMarkerPoint
private void CalcMarkerPoint()
{
if (Scale is GaugeCircularScale)
CalcCircularMarkerPoint(Scale as GaugeCircularScale);
}
#region CalcCircularMarkerPoint
private void CalcCircularMarkerPoint(GaugeCircularScale scale)
{
Dpt = scale.SweepAngle / scale.Spread;
double marker = GetInterval(Value) - scale.MinValue;
IntervalAngle = (float)(scale.Reversed
? scale.StartAngle + scale.SweepAngle - (marker * Dpt)
: scale.StartAngle + (marker * Dpt));
IntervalPoint = scale.GetPoint(Radius, IntervalAngle);
_CapWidth = (int)(scale.AbsRadius * GaugePointer.CapWidth);
if (_CapWidth % 2 != 0)
_CapWidth++;
int n = _CapWidth / 2;
_CapBounds = new Rectangle(
scale.Center.X - n, scale.Center.Y - n, _CapWidth, _CapWidth);
}
#endregion
#endregion
#endregion
#region RenderCircular
public override void RenderCircular(PaintEventArgs e)
{
if (IntervalPoint.IsEmpty == false && Radius > 0)
{
Graphics g = e.Graphics;
if (GaugePointer.CapOnTop == false)
RenderCap(g);
RenderNeedle(g);
if (GaugePointer.CapOnTop == true)
RenderCap(g);
}
}
#region RenderNeedle
#region RenderNeedle
private void RenderNeedle(Graphics g)
{
if (GaugePointer.NeedleStyle != NeedlePointerStyle.None)
{
g.TranslateTransform(IntervalPoint.X, IntervalPoint.Y);
g.RotateTransform((IntervalAngle + 90) % 360);
int length = Math.Max(Radius, Radius + Length);
if (Width > 0 && length > 0)
{
Rectangle r = new Rectangle(0, 0, Width, length);
r.X -= Width/2;
if (GaugePointer.Image != null)
{
g.DrawImage(GaugePointer.Image, r);
}
else
{
GradientFillColor fillColor = GaugePointer.FillColorEx;
if (fillColor != null)
{
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
? GradientFillType.Center
: fillColor.GradientFillType;
using (GraphicsPath path = GetNeedlePath(r))
{
RenderFill(g, r, path, fillColor, fillType, 0, false);
RenderBorder(g, path, fillColor);
}
}
}
}
g.ResetTransform();
}
}
#endregion
#region GetNeedlePath
private GraphicsPath GetNeedlePath(Rectangle r)
{
GaugeControl gc = GaugePointer.Scale.GaugeControl;
return (gc.OnGetPointerPath(GaugePointer, r) ?? GetNeedlePathEx(r));
}
private GraphicsPath GetNeedlePathEx(Rectangle r)
{
switch (GaugePointer.NeedleStyle)
{
case NeedlePointerStyle.Style1:
return (GetNeedlePathStyle1(r));
case NeedlePointerStyle.Style2:
return (GetNeedlePathStyle2(r));
case NeedlePointerStyle.Style3:
return (GetNeedlePathStyle3(r));
case NeedlePointerStyle.Style4:
return (GetNeedlePathStyle4(r));
case NeedlePointerStyle.Style5:
return (GetNeedlePathStyle5(r));
case NeedlePointerStyle.Style6:
return (GetNeedlePathStyle6(r));
case NeedlePointerStyle.Style7:
return (GetNeedlePathStyle7(r));
case NeedlePointerStyle.Style8:
return (GetNeedlePathStyle8(r));
default:
return (GetNeedlePathStyle1(r));
}
}
#region GetNeedlePathStyle1
private GraphicsPath GetNeedlePathStyle1(Rectangle r)
{
Point[] pts = new Point[]
{
new Point(r.Left, r.Bottom),
new Point(r.Left + (r.Width / 2), r.Top),
new Point(r.Right, r.Bottom),
};
GraphicsPath path = new GraphicsPath();
path.AddLines(pts);
path.CloseFigure();
return (path);
}
#endregion
#region GetNeedlePathStyle2
private GraphicsPath GetNeedlePathStyle2(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(r);
return (path);
}
#endregion
#region GetNeedlePathStyle3
private GraphicsPath GetNeedlePathStyle3(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
Rectangle t = r;
t.Height = t.Width;
path.AddArc(t, 180, 180);
t.Y = r.Bottom - t.Height;
path.AddArc(t, 0, 180);
path.CloseFigure();
return (path);
}
#endregion
#region GetNeedlePathStyle4
private GraphicsPath GetNeedlePathStyle4(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
Rectangle t = r;
t.Width = t.Width / 2;
t.Height = t.Width;
t.X += t.Width / 2;
path.AddArc(t, 180, 180);
path.AddLine(r.Right, r.Bottom, r.Left, r.Bottom);
path.CloseFigure();
return (path);
}
#endregion
#region GetNeedlePathStyle5
private GraphicsPath GetNeedlePathStyle5(Rectangle r)
{
int n = r.Width / 4;
Point[] pts = new Point[]
{
new Point(r.Left + n, r.Top + r.Width),
new Point(r.Left + r.Width / 2, r.Top),
new Point(r.Right - n, r.Top + r.Width)
};
GraphicsPath path = new GraphicsPath();
path.AddLines(pts);
path.AddLine(r.Right, r.Bottom, r.Left, r.Bottom);
path.CloseFigure();
return (path);
}
#endregion
#region GetNeedlePathStyle6
private GraphicsPath GetNeedlePathStyle6(Rectangle r)
{
if (r.Height <= Radius)
return (GetNeedlePathStyle1(r));
GraphicsPath path = new GraphicsPath();
Point[] pts = new Point[]
{
new Point(r.Left, r.Y + Radius),
new Point(r.Left + (r.Width / 2), r.Top),
new Point(r.Right, r.Y + Radius),
new Point(r.Left + (r.Width / 2), r.Bottom),
new Point(r.Left, r.Y + Radius),
};
path.AddLines(pts);
return (path);
}
#endregion
#region GetNeedlePathStyle7
private GraphicsPath GetNeedlePathStyle7(Rectangle r)
{
if (r.Height <= Radius)
return (GetNeedlePathStyle1(r));
GraphicsPath path = new GraphicsPath();
Point[] pts =
{
new Point(r.X + r.Width / 2, r.Y),
new Point(r.Right, r.Y + (r.Height / 3)),
new Point(r.Right - (r.Width / 4), r.Y + (r.Height / 3)),
new Point(r.Right, r.Bottom),
new Point(r.X + r.Width / 2, r.Bottom - r.Width / 2),
new Point(r.X, r.Bottom),
new Point(r.X + r.Width / 2, r.Y),
};
path.AddLines(pts);
return (path);
}
#endregion
#region GetNeedlePathStyle8
private GraphicsPath GetNeedlePathStyle8(Rectangle r)
{
if (r.Height <= Radius)
return (GetNeedlePathStyle1(r));
GraphicsPath path = new GraphicsPath();
Point[] pts = {
new Point(r.X + r.Width / 2, r.Y),
new Point(r.Right, r.Y + (r.Height / 3)),
new Point(r.Right - (r.Width / 4), r.Y + (r.Height / 3)),
new Point(r.Right, r.Bottom),
new Point(r.X + r.Width / 2, r.Bottom - r.Width / 2),
new Point(r.X, r.Bottom),
new Point(r.X + (r.Width / 4), r.Y + (r.Height / 3)),
new Point(r.X, r.Y + (r.Height / 3)),
};
path.AddLines(pts);
return (path);
}
#endregion
#endregion
#endregion
#region RenderCap
#region RenderCap
public void RenderCap(Graphics g)
{
if (_CapWidth > 2)
{
if (GaugePointer.CapImage != null)
RenderCapImage(g);
else
RenderCapStyle(g);
}
}
#region RenderCapStyle
private void RenderCapStyle(Graphics g)
{
if (GaugePointer.CapStyle != NeedlePointerCapStyle.None)
{
GradientFillColor fillColor = GaugePointer.CapFillColorEx;
if (fillColor != null)
{
GradientFillType fillType = (fillColor.GradientFillType == GradientFillType.Auto)
? GradientFillType.Angle
: fillColor.GradientFillType;
if (fillType == GradientFillType.Angle && fillColor.GradientAngle % 90 != 0)
{
Matrix myMatrix = new Matrix();
myMatrix.RotateAt(fillColor.GradientAngle, Scale.Center);
g.Transform = myMatrix;
}
switch (GaugePointer.CapStyle)
{
case NeedlePointerCapStyle.Style1:
RenderCapPathSytle1(g, _CapBounds, fillColor, fillType);
break;
case NeedlePointerCapStyle.Style2:
RenderCapPathSytle2(g, _CapBounds, fillColor, fillType);
break;
}
g.ResetTransform();
}
}
}
#endregion
#region RenderCapImage
private void RenderCapImage(Graphics g)
{
if (GaugePointer.RotateCap == true)
{
g.TranslateTransform(Scale.Center.X, Scale.Center.Y);
g.RotateTransform((IntervalAngle + 90) % 360);
Rectangle r = _CapBounds;
r.Location = new Point(-_CapBounds.Width / 2, -_CapBounds.Height / 2);
g.DrawImage(GaugePointer.CapImage, r);
g.ResetTransform();
}
else
{
g.DrawImage(GaugePointer.CapImage, _CapBounds);
}
}
#endregion
#endregion
#region RenderCapPathSytle1
private void RenderCapPathSytle1(Graphics g,
Rectangle r, GradientFillColor fillColor, GradientFillType fillType)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(r);
RenderFill(g, r, path, fillColor, fillType, 0, true);
RenderBorder(g, path, fillColor);
}
}
#endregion
#region RenderCapPathSytle2
private void RenderCapPathSytle2(Graphics g,
Rectangle r, GradientFillColor fillColor, GradientFillType fillType)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(r);
RenderFill(g, r, path, fillColor, fillType, 0, true);
RenderBorder(g, path, fillColor);
path.Reset();
int angle = 180;
int outer = (int)(r.Width * GaugePointer.CapOuterBevel);
if (outer > 0)
{
r.Inflate(-outer, -outer);
if (r.Width >= 2)
{
path.AddEllipse(r);
RenderFill(g, r, path, fillColor, fillType, 180, true);
path.Reset();
angle = 0;
}
}
int inner = (int) (r.Width*GaugePointer.CapInnerBevel);
if (inner > 0)
{
r.Inflate(-inner, -inner);
if (r.Width >= 2)
{
path.AddEllipse(r);
RenderFill(g, r, path, fillColor, fillType, angle, true);
}
}
}
}
#endregion
#endregion
#region RenderFill
private void RenderFill(Graphics g, Rectangle r, GraphicsPath path,
GradientFillColor fillColor, GradientFillType fillType, int angle, bool offset)
{
if (fillColor.Color2.IsEmpty)
fillType = GradientFillType.None;
switch (fillType)
{
case GradientFillType.Auto:
case GradientFillType.Angle:
if (offset == false)
angle += fillColor.GradientAngle;
using (Brush br = fillColor.GetBrush(r, angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.StartToEnd:
using (Brush br = fillColor.GetBrush(r, 90 + angle))
{
if (br is LinearGradientBrush)
((LinearGradientBrush)br).WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.HorizontalCenter:
if (r.Height >= 2)
r.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 90 + angle))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.VerticalCenter:
if (r.Width >= 2)
r.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(r, fillColor.Start, fillColor.End, 0f + angle))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillPath(br, path);
}
break;
case GradientFillType.Center:
using (PathGradientBrush br = new PathGradientBrush(path))
{
if (offset == true && Scale is GaugeCircularScale)
br.CenterPoint = ((GaugeCircularScale)Scale).GetPoint((int) (r.Width * .45f), 180 + 45 + angle);
br.CenterColor = fillColor.Start;
br.SurroundColors = new Color[] { fillColor.End };
g.FillPath(br, path);
}
break;
default:
using (Brush br = new SolidBrush(fillColor.Start))
g.FillPath(br, path);
break;
}
}
#endregion
#region RenderBorder
private void RenderBorder(
Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
if (fillColor.BorderWidth > 0)
{
using (Pen pen = new Pen(fillColor.BorderColor, fillColor.BorderWidth))
{
pen.Alignment = PenAlignment.Inset;
g.DrawPath(pen, path);
}
}
}
#endregion
#endregion
#region RenderLinear
public override void RenderLinear(PaintEventArgs e)
{
}
#endregion
#region GetPointerPath
public override GraphicsPath GetPointerPath()
{
if (PointerPath == null)
{
if (GaugePointer.NeedleStyle != NeedlePointerStyle.None)
{
int length = Math.Max(Radius, Radius + Length);
if (Width > 0 && length > 0)
{
Rectangle r = new Rectangle(IntervalPoint.X, IntervalPoint.Y, Width, length);
r.X -= Width / 2;
PointerPath = GetNeedlePath(r);
Matrix matrix = new Matrix();
matrix.RotateAt((IntervalAngle + 90) % 360, IntervalPoint);
PointerPath.Transform(matrix);
}
}
}
return (PointerPath);
}
#endregion
#region OnMouseDown
internal override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
GaugePointer.MouseDownAngle = IntervalAngle;
GaugePointer.MouseDownRadians = GetPointRadians(e.Location);
}
#endregion
#region IDisposable Members
public void Dispose()
{
PointerPath = null;
}
#endregion
}
#region Enums
public enum NeedlePointerStyle
{
None,
Style1,
Style2,
Style3,
Style4,
Style5,
Style6,
Style7,
Style8
}
public enum NeedlePointerCapStyle
{
None,
Style1,
Style2,
}
#endregion
}

View File

@@ -0,0 +1,563 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal abstract class GaugePointerRenderer
{
#region Private variables
private GaugePointer _GaugePointer;
private int _Width;
private int _Length;
private float _IntervalAngle;
private Point _IntervalPoint;
private double _Dpt;
private GraphicsPath _PointerPath;
#endregion
protected GaugePointerRenderer(GaugePointer gaugePointer)
{
_GaugePointer = gaugePointer;
}
#region Abstract methods
public abstract void RenderCircular(PaintEventArgs e);
public abstract void RenderLinear(PaintEventArgs e);
public abstract GraphicsPath GetPointerPath();
#endregion
#region Protected properties
#region GaugePointer
protected GaugePointer GaugePointer
{
get { return (_GaugePointer); }
}
#endregion
#region IntervalAngle
internal float IntervalAngle
{
get { return (_IntervalAngle); }
set { _IntervalAngle = value; }
}
#endregion
#region IntervalPoint
internal Point IntervalPoint
{
get { return (_IntervalPoint); }
set { _IntervalPoint = value; }
}
#endregion
#region Length
protected int Length
{
get { return (_Length); }
set { _Length = value; }
}
#endregion
#region MarkerStyle
protected GaugeMarkerStyle MarkerStyle
{
get { return (_GaugePointer.MarkerStyle); }
}
#endregion
#region PointerPath
internal GraphicsPath PointerPath
{
get { return (_PointerPath); }
set
{
if (_PointerPath != value)
{
if (_PointerPath != null)
_PointerPath.Dispose();
_PointerPath = value;
}
}
}
#endregion
#region Radius
protected int Radius
{
get { return (_GaugePointer.Radius); }
}
#endregion
#region Scale
protected GaugeScale Scale
{
get { return (_GaugePointer.Scale); }
}
#endregion
#region Value
protected double Value
{
get { return (_GaugePointer.DValue); }
}
#endregion
#region Width
protected int Width
{
get { return (_Width); }
set { _Width = value; }
}
#endregion
#endregion
#region Internal properties
#region Dpt
internal double Dpt
{
get { return (_Dpt > 0 ? _Dpt : 1); }
set { _Dpt = value; }
}
#endregion
#endregion
#region GetCapFillColor
protected GradientFillColor GetCapFillColor(double interval)
{
const ColorSourceFillEntry entry = ColorSourceFillEntry.Cap;
GradientFillColor fillColor = (Scale.GetRangeFillColor(interval, entry) ??
Scale.GetSectionFillColor(interval, entry)) ?? GaugePointer.CapFillColor;
return (fillColor);
}
#endregion
#region GetPointerFillColor
protected GradientFillColor GetPointerFillColor(double interval)
{
const ColorSourceFillEntry entry = ColorSourceFillEntry.Pointer;
GradientFillColor fillColor = (Scale.GetRangeFillColor(interval, entry) ??
Scale.GetSectionFillColor(interval, entry)) ?? GaugePointer.FillColor;
return (fillColor);
}
#endregion
#region GetInterval
internal double GetInterval(double interval)
{
bool pegged;
return (GetIntervalEx(interval, out pegged));
}
internal double GetInterval(double interval, out bool pegged)
{
double min, max;
GetRange(out min, out max);
pegged = true;
if (interval.Equals(double.NaN))
return (min);
if (interval < min)
interval = min;
else if (interval > max)
interval = max;
else
pegged = false;
return (interval);
}
internal double GetIntervalEx(double interval, out bool pegged)
{
int n = (GaugePointer.Scale is GaugeLinearScale)
? ((GaugeLinearScale) Scale).AbsLength
: 360;
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset*n)/Dpt : 0;
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset*n)/Dpt : 0;
double min = Scale.MinValue;
double max = Scale.MaxValue;
if (Scale.MinValue <= Scale.AbsMinLimit)
min -= minPinValue;
if (Scale.MaxValue >= Scale.AbsMaxLimit)
max += maxPinValue;
pegged = true;
if (interval.Equals(double.NaN))
return (min);
if (interval < min)
{
interval = Scale.MinValue > Scale.AbsMinLimit
? Math.Max(min - 1, Scale.AbsMinLimit)
: min;
}
else if (interval > max)
{
interval = Scale.MaxValue < Scale.AbsMaxLimit
? Math.Min(max + 1, Scale.AbsMaxLimit)
: max;
}
else
{
pegged = false;
}
return (interval);
}
#endregion
#region GetRange
internal void GetRange(out double min, out double max)
{
int n = (GaugePointer.Scale is GaugeLinearScale)
? ((GaugeLinearScale) Scale).AbsLength
: 360;
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset * n) / Dpt : 0;
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset * n) / Dpt : 0;
min = Scale.MinValue - minPinValue;
max = Scale.MaxValue + maxPinValue;
}
#endregion
#region GetRangeEx
internal void GetRangeEx(out double min, out double max)
{
int n = (GaugePointer.Scale is GaugeLinearScale)
? ((GaugeLinearScale)Scale).AbsLength
: 360;
double minPinValue = GaugePointer.HonorMinPin ? (Scale.MinPinEndOffset * n) / Dpt : 0;
double maxPinValue = GaugePointer.HonorMaxPin ? (Scale.MaxPinEndOffset * n) / Dpt : 0;
min = Scale.AbsMinLimit - minPinValue;
max = Scale.AbsMaxLimit + maxPinValue;
}
#endregion
#region SwapDoubles
protected void SwapDoubles(ref double marker, ref double origin)
{
double temp = marker;
marker = origin;
origin = temp;
}
#endregion
#region RecalcLayout
public virtual void RecalcLayout()
{
PointerPath = null;
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMetrics(Scale as GaugeLinearScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
_Width = (int)(scale.AbsRadius * GaugePointer.Width);
_Length = (int)(scale.AbsRadius * GaugePointer.Length);
if (_Width % 2 != 0)
_Width++;
}
#endregion
#region CalcLinearMetrics
private void CalcLinearMetrics(GaugeLinearScale scale)
{
int n = scale.AbsWidth;
_Width = (int)(n * GaugePointer.Width);
_Length = (int)(n * GaugePointer.Length);
if (_Width % 2 != 0)
_Width++;
}
#endregion
#endregion
#region GetValueFromPoint
public virtual double GetValueFromPoint(Point pt)
{
if (Scale is GaugeCircularScale)
return (GetCValueFromPoint(Scale as GaugeCircularScale, pt));
return (GetLValueFromPoint(Scale as GaugeLinearScale, pt));
}
#region GetCValueFromPoint
private double GetCValueFromPoint(GaugeCircularScale scale, Point pt)
{
double minValue = scale.MinValue;
double maxValue = scale.MaxValue;
double startAngle = scale.StartAngle;
double sweepAngle = scale.SweepAngle;
double radians = GetPointRadians(pt);
double spread = scale.MaxValue - scale.MinValue;
double dpt = spread / scale.SweepAngle;
if (minValue <= scale.AbsMinLimit)
minValue -= GetCMinPinOffset(dpt, ref startAngle, ref sweepAngle);
if (maxValue >= scale.AbsMaxLimit)
maxValue += GetCMaxPinOffset(dpt, ref startAngle, ref sweepAngle);
double angle = (GaugePointer.MouseDownAngle +
scale.GetDegrees(radians - GaugePointer.MouseDownRadians) - startAngle) % 360;
if (angle < 0)
angle += 360;
if (scale.Reversed == true)
{
angle = sweepAngle - angle;
if (angle < 0)
angle += 360;
}
if (angle < sweepAngle)
{
double value = angle * dpt + minValue;
if (GaugePointer.SnapInterval > 0)
value = (int)(value / GaugePointer.SnapInterval) * GaugePointer.SnapInterval;
return (value);
}
if (angle > sweepAngle + (360 - sweepAngle) / 2)
{
double limit = minValue;
if (limit > scale.AbsMinLimit)
limit = Math.Max(limit - 1, scale.AbsMinLimit);
return (limit);
}
double limit2 = maxValue;
if (limit2 < scale.AbsMaxLimit)
limit2 = Math.Min(limit2 + 1, scale.AbsMaxLimit);
return (limit2);
}
#region GetCMinPinOffset
private double GetCMinPinOffset(
double dpt, ref double startAngle, ref double sweepAngle)
{
if (GaugePointer.HonorMinPin == true)
{
double d = Scale.MinPinEndOffset * 360;
if (Scale.Reversed == false)
startAngle -= d;
sweepAngle += d;
return (d * dpt);
}
return (0);
}
#endregion
#region GetCMaxPinOffset
private double GetCMaxPinOffset(
double dpt, ref double startAngle, ref double sweepAngle)
{
if (GaugePointer.HonorMaxPin == true)
{
double d = Scale.MaxPinEndOffset * 360;
if (Scale.Reversed == true)
startAngle -= d;
sweepAngle += d;
return (d * dpt);
}
return (0);
}
#endregion
#region GetPointRadians
internal double GetPointRadians(Point pt)
{
int dx = pt.X - Scale.Center.X;
int dy = pt.Y - Scale.Center.Y;
if (dx >= 0)
{
if (dy >= 0)
return (Math.Atan((double)dy / dx));
return (-Math.Atan((double)dx / dy) + Math.PI * 1.5);
}
if (dy >= 0)
return (-Math.Atan((double)dx / dy) + Math.PI / 2);
return (Math.Atan((double)dy / dx) + Math.PI);
}
#endregion
#endregion
#region GetLValueFromPoint
private double GetLValueFromPoint(GaugeLinearScale scale, Point pt)
{
bool pegged;
double value = (scale.Orientation == Orientation.Horizontal)
? GetLhValueFromPoint(scale, pt, out pegged)
: GetLvValueFromPoint(scale, pt, out pegged);
if (GaugePointer.SnapInterval > 0)
{
if (pegged == false)
value = (int)(value / GaugePointer.SnapInterval) * GaugePointer.SnapInterval;
}
return (value);
}
#region GetLhValueFromPoint
private double GetLhValueFromPoint(GaugeLinearScale scale, Point pt, out bool pegged)
{
double spread = scale.MaxValue - scale.MinValue;
double tpd = spread / scale.ScaleBounds.Width;
double interval = (pt.X - scale.ScaleBounds.X) * tpd;
if (scale.Reversed == true)
return (GetIntervalEx(scale.MaxValue - interval, out pegged));
return (GetIntervalEx(scale.MinValue + interval, out pegged));
}
#endregion
#region GetLvValueFromPoint
private double GetLvValueFromPoint(GaugeLinearScale scale, Point pt, out bool pegged)
{
double spread = scale.MaxValue - scale.MinValue;
double tpd = spread / scale.ScaleBounds.Height;
double interval = (pt.Y - scale.ScaleBounds.Y) * tpd;
if (scale.Reversed == true)
return (GetIntervalEx(scale.MinValue + interval, out pegged));
return (GetIntervalEx(scale.MaxValue - interval, out pegged));
}
#endregion
#endregion
#endregion
#region OnMouseDown
internal virtual void OnMouseDown(MouseEventArgs e)
{
GaugePointer.MouseDownAngle = 0;
GaugePointer.MouseDownRadians = 0;
}
#endregion
}
}

View File

@@ -0,0 +1,636 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
internal class GaugeThermoRenderer : GaugeBarRenderer
{
#region Private variables
private Rectangle _BackBounds;
private Rectangle _BulbBounds;
#endregion
internal GaugeThermoRenderer(GaugePointer gaugePointer)
: base(gaugePointer)
{
}
#region RecalcLayout
#region CalcHorizontalMarkerBounds
protected override void CalcHorizontalMarkerBounds(GaugeLinearScale scale, int y)
{
int n = (int)(GaugePointer.BulbOffset * scale.ScaleBounds.Width);
if (Marker < Origin)
{
RoundAngle = 180;
int len = Math.Max(1, (int)((Origin - Marker) * Dpt) + n);
int x;
if (scale.Reversed == true)
{
x = scale.ScaleBounds.Right - (int)(Origin * Dpt) - n;
}
else
{
x = scale.ScaleBounds.X + (int)(Marker * Dpt);
int x2 = scale.ScaleBounds.X + (int)(Origin * Dpt) + n;
len = Math.Max(1, x2 - x + 1);
}
Bounds = new Rectangle(x, y, len, Width);
double maxMarker = GetInterval(double.MinValue) - scale.MinValue;
_BackBounds = Bounds;
_BackBounds.Width = (int)((Origin - maxMarker) * Dpt + n);
if (scale.Reversed == false)
_BackBounds.X = scale.ScaleBounds.Left + (int)(maxMarker * Dpt);
}
else
{
RoundAngle = 0;
int len = Math.Max(1, (int)((Marker - Origin) * Dpt) + n);
int x;
if (scale.Reversed == true)
x = scale.ScaleBounds.Right - (int)(Origin * Dpt) - len + n;
else
x = scale.ScaleBounds.X + (int)(Origin * Dpt) - n;
Bounds = new Rectangle(x, y, len, Width);
double maxMarker = GetInterval(double.MaxValue) - scale.MinValue;
_BackBounds = Bounds;
_BackBounds.Width = (int)((maxMarker - Origin) * Dpt + n);
if (scale.Reversed == true)
_BackBounds.X = scale.ScaleBounds.Right - (int)(maxMarker * Dpt) + 1;
}
}
#endregion
#region CalcVerticalMarkerBounds
protected override void CalcVerticalMarkerBounds(GaugeLinearScale scale, int x)
{
int n = (int)(GaugePointer.BulbOffset * scale.ScaleBounds.Height);
if (Marker < Origin)
{
RoundAngle = 90;
int len = Math.Max(1, (int)((Origin - Marker) * Dpt) + n);
int y;
if (scale.Reversed == true)
{
y = scale.ScaleBounds.Y + (int)(Marker * Dpt);
int y2 = scale.ScaleBounds.Y + (int)(Origin * Dpt) + n;
len = Math.Max(1, y2 - y);
}
else
{
y = scale.ScaleBounds.Bottom - (int)(Origin * Dpt) - n;
}
Bounds = new Rectangle(x, y, Width, len);
_BackBounds = Bounds;
double minMarker = GetInterval(double.MinValue) - scale.MinValue;
if (scale.Reversed == true)
{
_BackBounds.Y = scale.ScaleBounds.Top + (int)(minMarker * Dpt);
_BackBounds.Height = Bounds.Bottom - _BackBounds.Y;
}
else
{
_BackBounds.Height = (int)((Origin - minMarker) * Dpt + n);
}
}
else
{
RoundAngle = -90;
int len = Math.Max(1, (int)((Marker - Origin) * Dpt) + n);
int y;
if (scale.Reversed == true)
{
y = scale.ScaleBounds.Top + (int)(Origin * Dpt) - n;
}
else
{
y = scale.ScaleBounds.Bottom - (int)(Marker * Dpt);
int y2 = scale.ScaleBounds.Bottom - (int)(Origin * Dpt) + n;
len = Math.Max(1, y2 - y);
}
Bounds = new Rectangle(x, y, Width, len);
_BackBounds = Bounds;
double maxMarker = GetInterval(double.MaxValue) - scale.MinValue;
if (scale.Reversed == false)
{
_BackBounds.Y = scale.ScaleBounds.Bottom - (int)(maxMarker * Dpt);
_BackBounds.Height = Bounds.Bottom - _BackBounds.Y;
}
else
{
_BackBounds.Height = (int)((maxMarker - Origin) * Dpt + n);
}
}
}
#endregion
#endregion
#region RenderLinear
public override void RenderLinear(PaintEventArgs e)
{
Graphics g = e.Graphics;
GaugeLinearScale scale = Scale as GaugeLinearScale;
if (scale != null)
{
if (Bounds.Width > 0 && Bounds.Height > 0)
{
using (GraphicsPath path = GetBulbBackPath(scale))
RenderBar(g, path, GaugePointer.ThermoBackColor);
using (GraphicsPath path = GetBulbFillPath(scale))
RenderBar(g, path);
}
}
}
#region GetBulbBackPath
private GraphicsPath GetBulbBackPath(GaugeLinearScale scale)
{
return (GetBulbPath(scale, _BackBounds, 1));
}
#endregion
#region GetBulbFillPath
private GraphicsPath GetBulbFillPath(GaugeLinearScale scale)
{
return (GetBulbPath(scale, Bounds, 0));
}
#endregion
#region GetBulbPath
private GraphicsPath GetBulbPath(
GaugeLinearScale scale, Rectangle r, int inf)
{
GraphicsPath path = new GraphicsPath();
r.Inflate(inf, inf);
if (scale.Orientation == Orientation.Horizontal)
{
if (Marker < Origin != scale.Reversed)
return (GetHorizontalRightBulbPath(scale, path, r, inf));
return (GetHorizontalLeftBulbPath(scale, path, r, inf));
}
if (Marker < Origin != scale.Reversed)
return (GetVerticalTopBulbPath(scale, path, r, inf));
return (GetVerticalBottomBulbPath(scale, path, r, inf));
}
#region GetHorizontalLeftBulbPath
private GraphicsPath GetHorizontalLeftBulbPath(
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
AddLeftTube(path, t, inflate);
AddLeftBulb(scale, path, t, inflate);
path.CloseAllFigures();
return (path);
}
#region AddLeftTube
private void AddLeftTube(GraphicsPath path, Rectangle t, int inflate)
{
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
{
Point[] pts = new Point[] {
new Point(t.X, t.Y),
new Point(t.Right, t.Y),
new Point(t.Right, t.Bottom),
new Point(t.X, t.Bottom) };
path.AddLines(pts);
}
else
{
int x = Math.Max(t.Right - Width / 2, t.X);
int n = t.Right - x;
Rectangle r = new Rectangle(x - n, t.Y, n * 2, t.Height);
Point[] pts = new Point[] {
new Point(t.X, t.Y),
new Point (x, t.Y)};
path.AddLines(pts);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 270, 180);
}
else
{
path.AddLine(new Point(r.X + r.Width / 2, r.Y),
new Point(r.Right, r.Y + r.Height / 2));
}
pts = new Point[] {
new Point(x, t.Bottom),
new Point (t.X, t.Bottom)};
path.AddLines(pts);
}
}
#endregion
#region AddLeftBulb
private void AddLeftBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Height);
if (bulbRadius * 2 < t.Height)
bulbRadius = t.Height / 2;
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (t.Height * t.Height / 4)) + 4;
_BulbBounds = new Rectangle(
t.X - m - bulbRadius,
t.Y - bulbRadius + t.Height / 2, bulbRadius * 2, bulbRadius * 2);
if (inflate > 0)
_BulbBounds.Inflate(inflate, inflate);
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI);
path.AddArc(_BulbBounds, angle, 360 - (angle * 2));
}
#endregion
#endregion
#region GetHorizontalRightBulbPath
private GraphicsPath GetHorizontalRightBulbPath(
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
AddRightTube(path, t, inflate);
AddRightBulb(scale, path, t, inflate);
path.CloseAllFigures();
return (path);
}
#region AddRightTube
private void AddRightTube(GraphicsPath path, Rectangle t, int inflate)
{
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
{
Point[] pts = new Point[] {
new Point(t.Right, t.Bottom),
new Point(t.X, t.Bottom),
new Point(t.X, t.Y),
new Point(t.Right, t.Y) };
path.AddLines(pts);
}
else
{
int x = Math.Min(t.X + Width / 2, t.Right);
int n = x - t.X;
Rectangle r = new Rectangle(t.X, t.Y, n * 2, t.Height);
Point[] pts = new Point[] {
new Point(t.Right, t.Bottom),
new Point (x, t.Bottom)};
path.AddLines(pts);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 90, 180);
}
else
{
path.AddLine(new Point(r.X + r.Width / 2, r.Bottom),
new Point(r.X, r.Y + r.Height / 2));
}
pts = new Point[] {
new Point(x, t.Y),
new Point (t.Right, t.Y)};
path.AddLines(pts);
}
}
#endregion
#region AddRightBulb
private void AddRightBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Height);
if (bulbRadius * 2 < t.Height)
bulbRadius = t.Height / 2;
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (t.Height * t.Height / 4));
_BulbBounds = new Rectangle(
t.Right - bulbRadius + m,
t.Y - bulbRadius + t.Height / 2, bulbRadius * 2, bulbRadius * 2);
if (inflate > 0)
_BulbBounds.Inflate(inflate, inflate);
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI);
path.AddArc(_BulbBounds, angle + 180, 360 - (angle * 2));
}
#endregion
#endregion
#region GetVerticalBottomBulbPath
private GraphicsPath GetVerticalBottomBulbPath(
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
AddBottomTube(path, t, inflate);
AddBottomBulb(scale, path, t, inflate);
path.CloseAllFigures();
return (path);
}
#region AddBottomTube
private void AddBottomTube(GraphicsPath path, Rectangle t, int inflate)
{
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
{
Point[] pts = new Point[] {
new Point(t.X, t.Bottom),
new Point(t.X, t.Y),
new Point(t.Right, t.Y),
new Point(t.Right, t.Bottom) };
path.AddLines(pts);
}
else
{
int y = Math.Min(t.Y + t.Width / 2, t.Bottom);
int n = y - t.Y;
Rectangle r = new Rectangle(t.X, y - n, t.Width, n * 2);
Point[] pts = new Point[] {
new Point(t.X, t.Bottom),
new Point (t.X, y)};
path.AddLines(pts);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 180, 180);
}
else
{
path.AddLine(new Point(r.X, r.Y + r.Height / 2),
new Point(r.X + r.Width / 2, r.Y));
}
pts = new Point[] {
new Point(t.Right, y),
new Point (t.Right, t.Bottom)};
path.AddLines(pts);
}
}
#endregion
#region AddBottomBulb
private void AddBottomBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Width);
if (bulbRadius * 2 < t.Width)
bulbRadius = t.Width / 2;
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (Width * Width / 4)) + 4;
_BulbBounds = new Rectangle(
t.X - bulbRadius + t.Width / 2,
t.Bottom - bulbRadius + m - inflate, bulbRadius * 2, bulbRadius * 2);
if (inflate > 0)
_BulbBounds.Inflate(inflate, inflate);
float angle = ((GaugePointer.BulbStyle == BulbStyle.Flask)
? 90 : (float)(Math.Asin((double)(Width / 2) / bulbRadius) * 180 / Math.PI));
path.AddArc(_BulbBounds, angle + 270, 360 - (angle * 2));
}
#endregion
#endregion
#region GetVerticalTopBulbPath
private GraphicsPath GetVerticalTopBulbPath(
GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
AddTopTube(path, t, inflate);
AddTopBulb(scale, path, t, inflate);
path.CloseAllFigures();
return (path);
}
#region AddTopTube
private void AddTopTube(GraphicsPath path, Rectangle t, int inflate)
{
if (GaugePointer.BarStyle == BarPointerStyle.Square || inflate > 0)
{
Point[] pts = new Point[] {
new Point(t.Right, t.Y),
new Point(t.Right, t.Bottom),
new Point(t.X, t.Bottom),
new Point(t.X, t.Y) };
path.AddLines(pts);
}
else
{
int y = Math.Max(t.Bottom - t.Width / 2, t.Y);
int n = t.Bottom - y;
Rectangle r = new Rectangle(t.X, y - n, t.Width, n * 2);
Point[] pts = new Point[] {
new Point(t.Right, t.Y),
new Point(t.Right, y)};
path.AddLines(pts);
if (GaugePointer.BarStyle == BarPointerStyle.Rounded)
{
path.AddArc(r, 0, 180);
}
else
{
path.AddLine(new Point(r.Right, r.Y + r.Height / 2),
new Point(r.X + r.Width / 2, r.Bottom));
}
pts = new Point[] {
new Point(t.X, y),
new Point (t.X, t.Y)};
path.AddLines(pts);
}
}
#endregion
#region AddTopBulb
private void AddTopBulb(GaugeLinearScale scale, GraphicsPath path, Rectangle t, int inflate)
{
int bulbRadius = (int)(GaugePointer.BulbSize * scale.Bounds.Width);
if (bulbRadius * 2 < t.Width)
bulbRadius = t.Width / 2;
int m = (int)Math.Sqrt((bulbRadius * bulbRadius) - (Width * Width / 4));
_BulbBounds = new Rectangle(
t.X - bulbRadius + t.Width / 2,
t.Y - (bulbRadius + m) + inflate, bulbRadius * 2, bulbRadius * 2);
if (inflate > 0)
_BulbBounds.Inflate(inflate, inflate);
float angle = (GaugePointer.BulbStyle == BulbStyle.Flask)
? 90 : (float)(Math.Asin((double)(t.Width / 2) / bulbRadius) * 180 / Math.PI);
path.AddArc(_BulbBounds, angle + 90, 360 - (angle * 2));
}
#endregion
#endregion
#endregion
#region RenderBarByCenter
protected override void RenderBarByCenter(
Graphics g, GraphicsPath path, GradientFillColor fillColor)
{
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.WrapMode = WrapMode.TileFlipXY;
br.CenterColor = fillColor.Color1;
br.SurroundColors = new Color[] { fillColor.Color2 };
br.CenterPoint = new PointF(
_BulbBounds.X + _BulbBounds.Width / 2, _BulbBounds.Y + _BulbBounds.Height / 2);
g.FillPath(br, path);
}
}
#endregion
#endregion
#region GetPointerPath
public override GraphicsPath GetPointerPath()
{
if (PointerPath == null)
{
GaugeLinearScale scale = Scale as GaugeLinearScale;
if (scale != null)
{
if (Bounds.Width > 0 && Bounds.Height > 0)
PointerPath = GetBulbBackPath(scale);
}
}
return (PointerPath);
}
#endregion
}
#region Enums
public enum BulbStyle
{
Bulb,
Flask,
}
#endregion
}

View File

@@ -0,0 +1,590 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeCircularScales
/// </summary>
public class GaugeCircularScaleCollection : GenericCollection<GaugeCircularScale>
{
}
[TypeConverter(typeof(GaugeScaleConvertor))]
public class GaugeCircularScale : GaugeScale
{
#region Private variables
private float _StartAngle;
private float _SweepAngle;
private float _Radius;
private PointF _PivotPoint;
private int _SquareSize;
#endregion
public GaugeCircularScale(GaugeControl gaugeControl)
: base(gaugeControl)
{
InitGaugeScale();
}
public GaugeCircularScale()
{
InitGaugeScale();
}
#region InitGaugeScale
private void InitGaugeScale()
{
Style = GaugeScaleStyle.Circular;
_PivotPoint = new PointF(.5f, .5f);
Radius = .38f;
StartAngle = 110;
SweepAngle = 320;
Width = .065f;
}
#endregion
#region Public properties
#region PivotPoint
/// <summary>
/// Gets or sets the Scale pivot point, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.PivotPointEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Scale pivot point, specified as a percentage.")]
[TypeConverter(typeof(PointFConverter))]
public PointF PivotPoint
{
get { return (_PivotPoint); }
set
{
if (_PivotPoint.Equals(value) == false)
{
_PivotPoint = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializePivotPoint()
{
return (_PivotPoint.X != .5f || _PivotPoint.Y != .5f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetPivotPoint()
{
_PivotPoint = new PointF(.5f, .5f);
}
#endregion
#region Radius
/// <summary>
/// Gets or sets the Radius of Scale, specified as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(.38f)]
[Editor("DevComponents.Instrumentation.Design.RadiusRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Radius of Scale, specified as a percentage.")]
[NotifyParentProperty(true)]
public float Radius
{
get { return (_Radius); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_Radius != value)
{
_Radius = value;
NeedLabelRecalcLayout = true;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region StartAngle
/// <summary>
/// Gets and sets the angle measured from the x-axis to the starting point of the scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(110f)]
[Description("Indicates the angle measured from the x-axis to the starting point of the scale.")]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
public float StartAngle
{
get { return (_StartAngle); }
set
{
if (value < 0 || value > 360)
throw new ArgumentException("Value must be between 0 and 360 degrees.");
if (_StartAngle != value)
{
_StartAngle = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region SweepAngle
/// <summary>
/// Get and sets the angle measured from the StartAngle to the ending point of the scale.
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(320f)]
[Description("Indicates the angle measured from the StartAngle to the ending point of the scale.")]
[Editor("DevComponents.Instrumentation.Design.AngleRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
public float SweepAngle
{
get { return (_SweepAngle); }
set
{
if (value < 0 || value > 360)
throw new ArgumentException("Value must be between -0 and +360.");
if (_SweepAngle != value)
{
_SweepAngle = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region AbsRadius
internal int AbsRadius
{
get { return (int)(SquareSize * _Radius); }
}
#endregion
#region AbsScaleWidth
internal int AbsScaleWidth
{
get { return (int)(AbsRadius * Width); }
}
#endregion
#region SquareSize
internal int SquareSize
{
get { return (_SquareSize); }
set { _SquareSize = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
RecalcMetrics();
NeedLabelRecalcLayout = true;
NeedSectionRecalcLayout = true;
NeedRangeRecalcLayout = true;
NeedTickMarkRecalcLayout = true;
NeedPointerRecalcLayout = true;
NeedPinRecalcLayout = true;
base.RecalcLayout();
}
}
#region RecalcMetrics
private void RecalcMetrics()
{
base.RecalcLayout();
bool autoCenter = GaugeControl.Frame.AutoCenter;
_SquareSize = GaugeControl.GetAbsSize(new SizeF(1, 1), true).Width;
Center = GaugeControl.GetAbsPoint(_PivotPoint, autoCenter);
int radius = (int)(_Radius * _SquareSize);
Rectangle r = new Rectangle();
r.Size = new Size(radius * 2, radius * 2);
r.Location = new Point(Center.X - r.Size.Width / 2, Center.Y - r.Size.Height / 2);
Bounds = r;
}
#endregion
#endregion
#region PaintBorder
protected override void PaintBorder(PaintEventArgs e)
{
Graphics g = e.Graphics;
if (BorderWidth > 0)
{
int radius = AbsRadius;
int n = (int) (radius*Width);
if (radius > 0 && n > 0)
{
using (GraphicsPath path = new GraphicsPath())
{
Rectangle r = Bounds;
r.Inflate(n/2, n/2);
path.AddArc(r, _StartAngle, _SweepAngle);
r.Inflate(-n, -n);
path.AddArc(r, _StartAngle + _SweepAngle, -_SweepAngle);
path.CloseAllFigures();
using (Pen pen = new Pen(BorderColor, BorderWidth))
g.DrawPath(pen, path);
}
}
}
}
#endregion
#region GetPoint
internal Point GetPoint(int radius, float angle)
{
Point pt = new Point();
// Normalize the angle and calculate some
// working vars
if (angle < 0)
angle += 360;
angle = angle % 360;
// Determine the angle quadrant, and then calculate
// the intersecting coordinate accordingly
double radians = GetRadians(angle % 90);
if (angle < 90)
{
pt.X = (int)(Math.Cos(radians) * radius);
pt.Y = (int)(Math.Sin(radians) * radius);
}
else if (angle < 180)
{
pt.X = -(int)(Math.Sin(radians) * radius);
pt.Y = (int)(Math.Cos(radians) * radius);
}
else if (angle < 270)
{
pt.X = -(int)(Math.Cos(radians) * radius);
pt.Y = -(int)(Math.Sin(radians) * radius);
}
else
{
pt.X = (int)(Math.Sin(radians) * radius);
pt.Y = -(int)(Math.Cos(radians) * radius);
}
pt.X += Center.X;
pt.Y += Center.Y;
return (pt);
}
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
private double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region GetDegrees
internal double GetDegrees(double radians)
{
return (radians * 180 / Math.PI);
}
#endregion
#region GetRadiansFromPoint
/// <summary>
/// Gets the angle (in radians) of the given point on the scale.
/// </summary>
/// <param name="pt"></param>
/// <returns>Angle, in radians</returns>
public double GetRadiansFromPoint(Point pt)
{
double radians = GetPointRadians(pt);
return (radians);
}
#endregion
#region GetDegreesFromPoint
/// <summary>
/// Gets the angle (in degrees) of the given point on the scale.
/// </summary>
/// <param name="pt"></param>
/// <returns>Angle, in degrees</returns>
public double GetDegreesFromPoint(Point pt)
{
return (GetDegrees(GetRadiansFromPoint(pt)));
}
#endregion
#region GetPointRadians
internal double GetPointRadians(Point pt)
{
int dx = pt.X - Center.X;
int dy = pt.Y - Center.Y;
if (dx >= 0)
{
if (dy >= 0)
return (Math.Atan((double)dy / dx));
return (-Math.Atan((double)dx / dy) + Math.PI * 1.5);
}
if (dy >= 0)
return (-Math.Atan((double)dx / dy) + Math.PI / 2);
return (Math.Atan((double)dy / dx) + Math.PI);
}
#endregion
#region GetNearLabelRadius
internal int GetNearLabelRadius()
{
int scaleRadius = AbsRadius;
int scaleWidth = AbsScaleWidth;
int radius = scaleRadius - scaleWidth / 2;
radius = GetNearLabelRadius(MajorTickMarks, scaleRadius, radius);
radius = GetNearLabelRadius(MinorTickMarks, scaleRadius, radius);
return (radius);
}
private int GetNearLabelRadius(GaugeTickMark tickMarks, int scaleRadius, int radius)
{
if (tickMarks.Visible == true)
{
int tickMarkRadius = tickMarks.Radius;
if (tickMarks.Layout.Placement != DisplayPlacement.Near)
tickMarkRadius -= (int)(tickMarks.Layout.Length * scaleRadius);
if (tickMarkRadius < radius)
radius = tickMarkRadius;
}
return (radius);
}
#endregion
#region GetFarLabelRadius
internal int GetFarLabelRadius()
{
int scaleRadius = AbsRadius;
int scaleWidth = AbsScaleWidth;
int radius = scaleRadius + scaleWidth / 2;
radius = GetFarLabelRadius(MajorTickMarks, scaleRadius, radius);
radius = GetFarLabelRadius(MinorTickMarks, scaleRadius, radius);
return (radius);
}
private int GetFarLabelRadius(GaugeTickMark tickMarks, int scaleRadius, int radius)
{
if (tickMarks.Visible == true)
{
int tickMarkRadius = tickMarks.Radius;
if (tickMarks.Layout.Placement == DisplayPlacement.Near)
tickMarkRadius += (int)(tickMarks.Layout.Length * scaleRadius);
if (tickMarkRadius > radius)
radius = tickMarkRadius;
}
return (radius);
}
#endregion
#region CreateGradient
internal PathGradientBrush CreateGradient(Rectangle r,
float startAngle, float sweepAngle, GradientFillColor fillColor, int n)
{
r.Inflate(n, n);
const int count = 15;
int k = (sweepAngle > 0 ? -1 : 1);
float sa = startAngle + k;
float ea = sa + sweepAngle;
float n1 = (sweepAngle - k) / count;
PointF[] pts = new PointF[count + 1];
Color[] cls = new Color[count + 1];
Color c1 = fillColor.Start;
Color c2 = fillColor.End.IsEmpty == false ? fillColor.End : fillColor.Start;
// Calculate the RGB color deltas
float dr = (float)(c2.R - c1.R) / count;
float dg = (float)(c2.G - c1.G) / count;
float db = (float)(c2.B - c1.B) / count;
int radius = r.Width / 2;
for (int i = 0; i < count; i++)
{
pts[i] = GetPoint(radius, sa + i * n1);
Color c3 = Color.FromArgb(
(int)(c1.R + dr * i),
(int)(c1.G + dg * i),
(int)(c1.B + db * i));
cls[i] = c3;
}
float d = Math.Abs(sweepAngle);
float delta = (d < 180 ? (180 - d) : 2);
pts[count] = GetPoint(radius, ea + (sweepAngle < 0 ? -delta : delta));
cls[count] = c2;
PathGradientBrush pgb = new PathGradientBrush(pts);
pgb.CenterColor = Color.White;
pgb.CenterPoint = Center;
pgb.SurroundColors = cls;
pgb.FocusScales = new PointF(0f, 0f);
Blend blnd = new Blend();
blnd.Positions = new float[] { 0f, 1f };
blnd.Factors = new float[] { 1f, 1f };
pgb.Blend = blnd;
return (pgb);
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeCircularScale copy = new GaugeCircularScale();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeCircularScale c = copy as GaugeCircularScale;
if (c != null)
{
base.CopyToItem(c);
c.PivotPoint = _PivotPoint;
c.Radius = _Radius;
c.StartAngle = _StartAngle;
c.SweepAngle = _SweepAngle;
}
}
#endregion
}
}

View File

@@ -0,0 +1,357 @@
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeLinearScales
/// </summary>
public class GaugeLinearScaleCollection : GenericCollection<GaugeLinearScale>
{
}
[TypeConverter(typeof(GaugeScaleConvertor))]
public class GaugeLinearScale : GaugeScale
{
#region Private variables
private SizeF _Size;
private PointF _Location;
private Orientation _Orientation;
private Rectangle _ScaleBounds;
#endregion
public GaugeLinearScale(GaugeControl gaugeControl)
: base(gaugeControl)
{
InitGaugeScale();
}
public GaugeLinearScale()
{
InitGaugeScale();
}
#region InitGaugeScale
private void InitGaugeScale()
{
Style = GaugeScaleStyle.Linear;
_Location = new PointF(.5f, .5f);
_Size = new SizeF(.8f, .8f);
_Orientation = Orientation.Horizontal;
}
#endregion
#region Public properties
#region Location
/// <summary>
/// Gets or sets the Scale location, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.LocationEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Scale location, specified as a percentage.")]
[TypeConverter(typeof(PointFConverter))]
public PointF Location
{
get { return (_Location); }
set
{
if (_Location.Equals(value) == false)
{
_Location = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializePivotPoint()
{
return (_Location.X != .5f || _Location.Y != .5f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetPivotPoint()
{
_Location = new PointF(.5f, .5f);
}
#endregion
#region Orientation
/// <summary>
/// Gets or sets the Scale display orientation
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(Orientation.Horizontal)]
[Description("Indicates the Scale display orientation.")]
public Orientation Orientation
{
get { return (_Orientation); }
set
{
if (_Orientation != value)
{
_Orientation = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region ReverseScalingAxis
private bool _ReverseScalingAxis;
/// <summary>
/// Gets or sets whether linear scales are scaled
/// using the default axis or not.
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(false)]
[Description("Indicates whether linear scales are scaled using the default axis or not.")]
public bool ReverseScalingAxis
{
get { return (_ReverseScalingAxis); }
set
{
if (_ReverseScalingAxis != value)
{
_ReverseScalingAxis = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region Size
/// <summary>
/// Gets or sets the bounding size of the Scale, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.SizeEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Determines the bounding size of the Scale, specified as a percentage.")]
public SizeF Size
{
get { return (_Size); }
set
{
if (_Size != value)
{
_Size = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeSize()
{
return (_Size.Width != .8f || _Size.Height != .8f);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetSize()
{
_Size = new SizeF(.8f, .8f);
}
#endregion
#endregion
#region Internal properties
#region AbsLength
internal int AbsLength
{
get
{
if (_Orientation == Orientation.Horizontal)
return (Bounds.Width);
return (Bounds.Height);
}
}
#endregion
#region AbsWidth
internal int AbsWidth
{
get
{
if (_Orientation == Orientation.Horizontal)
return (_ReverseScalingAxis ? Bounds.Width : Bounds.Height);
return (_ReverseScalingAxis ? Bounds.Height : Bounds.Width);
}
}
#endregion
#region AbsScaleLength
internal int AbsScaleLength
{
get
{
if (_Orientation == Orientation.Horizontal)
return (_ScaleBounds.Width);
return (_ScaleBounds.Height);
}
}
#endregion
#region AbsScaleWidth
internal int AbsScaleWidth
{
get
{
if (_Orientation == Orientation.Horizontal)
return (_ScaleBounds.Height);
return (_ScaleBounds.Width);
}
}
#endregion
#region ScaleBounds
internal Rectangle ScaleBounds
{
get { return (_ScaleBounds); }
set { _ScaleBounds = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
RecalcMetrics();
}
}
#region RecalcMetrics
private void RecalcMetrics()
{
Center = GaugeControl.GetAbsPoint(_Location, false);
Rectangle r = new Rectangle();
r.Size = GaugeControl.GetAbsSize(_Size, false);
r.Location = new Point(Center.X - r.Size.Width / 2, Center.Y - r.Size.Height / 2);
Bounds = r;
_ScaleBounds = new Rectangle();
if (Orientation == Orientation.Horizontal)
{
if (ReverseScalingAxis == true)
_ScaleBounds.Size = new Size(r.Width, (int)(r.Width * Width));
else
_ScaleBounds.Size = new Size(r.Width, (int)(r.Height * Width));
_ScaleBounds.Location = new Point(r.X, Center.Y - _ScaleBounds.Size.Height / 2);
}
else
{
if (ReverseScalingAxis == true)
_ScaleBounds.Size = new Size((int)(r.Height * Width), r.Height);
else
_ScaleBounds.Size = new Size((int)(r.Width * Width), r.Height);
_ScaleBounds.Location = new Point(Center.X - _ScaleBounds.Size.Width / 2, r.Y);
}
}
#endregion
#endregion
#region PaintBorder
protected override void PaintBorder(PaintEventArgs e)
{
if (BorderWidth > 0)
{
if (Bounds.Width > 0 && Bounds.Height > 0)
{
using (Pen pen = new Pen(BorderColor, BorderWidth))
e.Graphics.DrawRectangle(pen, _ScaleBounds);
}
}
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeLinearScale copy = new GaugeLinearScale();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeLinearScale c = copy as GaugeLinearScale;
if (c != null)
{
base.CopyToItem(c);
c.Location = _Location;
c.Orientation = _Orientation;
c.Size = _Size;
}
}
#endregion
}
}

View File

@@ -0,0 +1,674 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Windows.Forms;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
/// <summary>
/// Collection of GaugeSections
/// </summary>
public class GaugeSectionCollection : GenericCollection<GaugeSection>
{
#region ICloneable Members
public override object Clone()
{
GaugeSectionCollection copy = new GaugeSectionCollection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal void CopyToItem(GaugeSectionCollection copy)
{
foreach (GaugeSection item in this)
{
GaugeSection ic = new GaugeSection();
item.CopyToItem(ic);
copy.Add(ic);
}
}
#endregion
}
[TypeConverter(typeof(GaugeSectionConvertor))]
public class GaugeSection : GaugeStrip
{
#region Private variables
private float _Width;
private int _AbsWidth;
#endregion
public GaugeSection(GaugeScale scale)
: base(scale)
{
}
public GaugeSection()
{
}
#region Public properties
#region Width
/// <summary>
/// Gets or sets the Width of the Section, specified as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(.0f)]
[Editor("DevComponents.Instrumentation.Design.WidthRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Width of the Section, specified as a percentage.")]
public float Width
{
get { return (_Width); }
set
{
if (value < 0 || value > 1)
throw new ArgumentException("Width must be between 0 and 1.");
if (_Width != value)
{
_Width = value;
OnGaugeItemChanged();
}
}
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
base.RecalcLayout();
if (Scale is GaugeCircularScale)
CalcCircularLayout(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearLayout(Scale as GaugeLinearScale);
}
#region CalcCircularLayout
private void CalcCircularLayout(GaugeCircularScale scale)
{
int radius = scale.AbsRadius;
int scaleOffset = (int)(radius * ScaleOffset);
_AbsWidth = (int)(radius * (_Width > 0 ? _Width : scale.Width));
Rectangle r = scale.Bounds;
r.Inflate(scaleOffset, scaleOffset);
Bounds = r;
}
#endregion
#region CalcLinearLayout
#region CalcLinearLayout
private void CalcLinearLayout(GaugeLinearScale scale)
{
float spread = (float)(scale.MaxValue - scale.MinValue);
if (spread == 0)
spread = 1;
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalLayout(scale, spread);
else
CalcVerticalLayout(scale, spread);
}
#endregion
#region CalcHorizontalLayout
private void CalcHorizontalLayout(GaugeLinearScale scale, float spread)
{
int length = scale.ScaleBounds.Width;
int width = scale.ScaleBounds.Height;
float dl = length / spread;
int start = (int)(dl * MinValue);
int len = (int)(dl * (MaxValue - MinValue));
int offset = (int)(width * ScaleOffset);
_AbsWidth = (int)(_Width > 0 ? width * _Width : width);
Rectangle r = scale.Bounds;
if (scale.Reversed == true)
r.X = r.Right - (start + len);
else
r.X += start;
r.Width = len;
r.Y = scale.Center.Y - (_AbsWidth / 2) + offset;
r.Height = _AbsWidth;
Bounds = r;
}
#endregion
#region CalcVerticalLayout
private void CalcVerticalLayout(GaugeLinearScale scale, float spread)
{
int length = scale.ScaleBounds.Height;
int width = scale.ScaleBounds.Width;
int n = width;
float dl = length / spread;
int start = (int)(dl * MinValue);
int len = (int)(dl * (MaxValue - MinValue));
int offset = (int)(length * ScaleOffset);
_AbsWidth = (int)(_Width > 0 ? n * _Width : n);
Rectangle r = scale.Bounds;
if (scale.Reversed == true)
r.Y += start;
else
r.Y = r.Bottom - (start + len);
r.X = scale.Center.X - (_AbsWidth / 2) + offset;
r.Width = _AbsWidth;
r.Height = len;
Bounds = r;
}
#endregion
#endregion
#endregion
#region OnPaint
public override void OnPaint(PaintEventArgs e)
{
RecalcLayout();
if (Scale.GaugeControl.OnPreRenderScaleSection(e, this) == false)
{
if (Scale is GaugeCircularScale)
{
if (SweepAngle != 0)
PaintCircularSection(e, Scale as GaugeCircularScale);
}
else if (Scale is GaugeLinearScale)
{
PaintLinearSection(e, Scale as GaugeLinearScale);
}
Scale.GaugeControl.OnPostRenderScaleSection(e, this);
}
}
#endregion
#region PaintCircularSection
#region PaintCircularSection
private void PaintCircularSection(PaintEventArgs e, GaugeCircularScale scale)
{
Graphics g = e.Graphics;
int radius = scale.AbsRadius;
int n = (int)(radius * (_Width > 0 ? _Width : scale.Width));
if (n > 0 && Bounds.Width > 0 && Bounds.Height > 0 && Math.Abs(SweepAngle) > .05)
{
if (FillColor.End.IsEmpty == true || FillColor.Color1 == FillColor.Color2 ||
FillColor.GradientFillType == GradientFillType.None)
{
using (Pen pen = new Pen(FillColor.Color1, n))
g.DrawArc(pen, Bounds, StartAngle, SweepAngle);
}
else
{
switch (FillColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.StartToEnd:
PaintCircularStartToEnd(g, Bounds, n, scale);
break;
case GradientFillType.Angle:
PaintCircularByAngle(g, Bounds, n);
break;
case GradientFillType.Center:
PaintCircularByCenter(g, Bounds, n);
break;
case GradientFillType.HorizontalCenter:
PaintCircularByHc(g, Bounds, n);
break;
case GradientFillType.VerticalCenter:
PaintCircularByVc(g, Bounds, n);
break;
}
}
}
}
#endregion
#region PaintCircularStartToEnd
private void PaintCircularStartToEnd(Graphics g,
Rectangle r, int n, GaugeCircularScale scale)
{
using (PathGradientBrush br = scale.CreateGradient(
Scale.GaugeControl.Frame.Bounds, StartAngle, SweepAngle, FillColor, 10))
{
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByAngle
private void PaintCircularByAngle(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Inflate(10, 10);
using (Brush br = FillColor.GetBrush(t))
{
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByCenter
private void PaintCircularByCenter(Graphics g, Rectangle r, int n)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddArc(r, StartAngle, SweepAngle);
using (Pen pen = new Pen(Color.Black, n))
path.Widen(pen);
using (PathGradientBrush br = new PathGradientBrush(path))
{
br.CenterColor = FillColor.Color1;
br.SurroundColors = new Color[] {FillColor.Color2};
br.CenterPoint = Scale.Center;
float m = (float)n / (r.Width / 2);
Blend blnd = new Blend();
blnd.Positions = new float[] { 0f, m, 1f };
blnd.Factors = new float[] { 1f, 0f, 0f };
br.Blend = blnd;
g.FillPath(br, path);
}
}
}
#endregion
#region PaintCircularByHc
private void PaintCircularByHc(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#region PaintCircularByVc
private void PaintCircularByVc(Graphics g, Rectangle r, int n)
{
Rectangle t = r;
t.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
using (Pen pen = new Pen(br, n))
g.DrawArc(pen, r, StartAngle, SweepAngle);
}
}
#endregion
#endregion
#region PaintLinearSection
#region PaintLinearSection
private void PaintLinearSection(PaintEventArgs e, GaugeLinearScale scale)
{
Graphics g = e.Graphics;
if (Bounds.Width > 0 && Bounds.Height > 0)
{
if (FillColor.End.IsEmpty == true || FillColor.Color1 == FillColor.Color2 ||
FillColor.GradientFillType == GradientFillType.None)
{
using (Brush br = new SolidBrush(FillColor.Color1))
g.FillRectangle(br, Bounds);
}
else
{
switch (FillColor.GradientFillType)
{
case GradientFillType.Auto:
case GradientFillType.StartToEnd:
PaintLinearStartToEnd(g, Bounds, scale);
break;
case GradientFillType.Angle:
PaintLinearByAngle(g, Bounds);
break;
case GradientFillType.Center:
PaintLinearByCenter(g, Bounds);
break;
case GradientFillType.HorizontalCenter:
PaintLinearByHc(g, Bounds);
break;
case GradientFillType.VerticalCenter:
PaintLinearByVc(g, Bounds);
break;
}
}
}
}
#endregion
#region PaintLinearStartToEnd
private void PaintLinearStartToEnd(
Graphics g, Rectangle r, GaugeLinearScale scale)
{
int angle = scale.Orientation == Orientation.Horizontal ? 0 : -90;
if (scale.Reversed == true)
angle += 180;
using (Brush br = FillColor.GetBrush(r, angle))
g.FillRectangle(br, r);
}
#endregion
#region PaintLinearByAngle
private void PaintLinearByAngle(Graphics g, Rectangle r)
{
using (Brush br = FillColor.GetBrush(r))
g.FillRectangle(br, r);
}
#endregion
#region PaintLinearByCenter
private void PaintLinearByCenter(Graphics g, Rectangle r)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(r);
using (PathGradientBrush br = new PathGradientBrush(path))
{
Point pt = new Point(r.X + r.Width / 2, r.Y + r.Height / 2);
br.CenterColor = FillColor.Color1;
br.SurroundColors = new Color[] { FillColor.Color2 };
br.CenterPoint = pt;
g.FillPath(br, path);
}
}
}
#endregion
#region PaintLinearByHc
private void PaintLinearByHc(Graphics g, Rectangle r)
{
Rectangle t = r;
if (r.Height >= 2)
t.Height /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 90))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
}
#endregion
#region PaintLinearByVc
private void PaintLinearByVc(Graphics g, Rectangle r)
{
Rectangle t = r;
if (t.Width >= 2)
t.Width /= 2;
using (LinearGradientBrush br = new
LinearGradientBrush(t, FillColor.Color1, FillColor.Color2, 0f))
{
br.WrapMode = WrapMode.TileFlipXY;
g.FillRectangle(br, r);
}
}
#endregion
#endregion
#region FindItem
internal override GaugeItem FindItem(Point pt)
{
GraphicsPath path = GetSectionPath();
if (path != null)
{
if (path.IsVisible(pt) == true)
return (this);
}
return (null);
}
#endregion
#region GetSectionPath
public GraphicsPath GetSectionPath()
{
if (StripePath == null)
{
if (Scale is GaugeCircularScale)
StripePath = GetCSectionPath(Scale as GaugeCircularScale);
else
StripePath = GetLSectionPath();
}
return (StripePath);
}
#endregion
#region GetCSectionPath
private GraphicsPath GetCSectionPath(GaugeCircularScale scale)
{
int radius = scale.AbsRadius;
int n = (int)(radius * (_Width > 0 ? _Width : scale.Width));
if (n > 0 && Bounds.Width > 0 && Bounds.Height > 0)
{
GraphicsPath path = new GraphicsPath();
Rectangle r = Bounds;
r.Inflate(n / 2, n / 2);
path.AddArc(r, StartAngle, SweepAngle);
r.Inflate(-n, -n);
path.AddArc(r, StartAngle + SweepAngle, -SweepAngle);
path.CloseAllFigures();
return (path);
}
return (null);
}
#endregion
#region GetLSectionPath
private GraphicsPath GetLSectionPath()
{
if (Bounds.Width > 0 && Bounds.Height > 0)
{
GraphicsPath path = new GraphicsPath();
path.AddRectangle(Bounds);
return (path);
}
return (null);
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeSection copy = new GaugeSection();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeSection c = copy as GaugeSection;
if (c != null)
{
base.CopyToItem(c);
c.Width = _Width;
}
}
#endregion
}
#region GaugeScaleConvertor
public class GaugeSectionConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeSection section = value as GaugeSection;
if (section != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,776 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Text;
namespace DevComponents.Instrumentation
{
public class GaugeStrip : GaugeItem, IDisposable
{
#region Events
[Description("Occurs when the coverage of a Strip changes.")]
public event EventHandler<EventArgs> StripCoverChanged;
#endregion
#region Private variables
private double _StartValue;
private double _EndValue;
private float _ScaleOffset;
private GradientFillColor _FillColor;
private Color _LabelColor;
private GradientFillColor _CapFillColor;
private GradientFillColor _PointerFillColor;
private GradientFillColor _MajorTickMarkFillColor;
private GradientFillColor _MinorTickMarkFillColor;
private GaugeScale _Scale;
private float _StartAngle;
private float _SweepAngle;
private double _MinValue;
private double _MaxValue;
private Rectangle _Bounds;
private GraphicsPath _StripePath;
#endregion
public GaugeStrip(GaugeScale scale)
: this()
{
_Scale = scale;
}
public GaugeStrip()
{
FillColor = new GradientFillColor();
_StartValue = double.NaN;
_EndValue = double.NaN;
}
#region Public properties
#region CapFillColor
/// <summary>
/// Gets or sets the Cap Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Cap Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor CapFillColor
{
get
{
if (_CapFillColor == null)
{
_CapFillColor = new GradientFillColor();
_CapFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
}
return (_CapFillColor);
}
set
{
if (_CapFillColor != null)
_CapFillColor.ColorTableChanged -= PointerFillColor_ColorTableChanged;
_CapFillColor = value;
if (_CapFillColor != null)
_CapFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region EndValue
/// <summary>
/// Gets or sets the Ending value for the area
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(double.NaN)]
[Description("Indicates the Ending value for the area.")]
public double EndValue
{
get { return (_EndValue); }
set
{
if (_EndValue != value)
{
_EndValue = value;
OnStripCoverChanged();
}
}
}
#endregion
#region PointerFillColor
/// <summary>
/// Gets or sets the Pointer Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Pointer Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor PointerFillColor
{
get
{
if (_PointerFillColor == null)
{
_PointerFillColor = new GradientFillColor();
_PointerFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
}
return (_PointerFillColor);
}
set
{
if (_PointerFillColor != null)
_PointerFillColor.ColorTableChanged -= PointerFillColor_ColorTableChanged;
_PointerFillColor = value;
if (_PointerFillColor != null)
_PointerFillColor.ColorTableChanged += PointerFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region FillColor
/// <summary>
/// Gets or sets the area Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the area Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor FillColor
{
get
{
if (_FillColor == null)
{
_FillColor = new GradientFillColor();
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
}
return (_FillColor);
}
set
{
if (_FillColor != null)
_FillColor.ColorTableChanged -= FillColor_ColorTableChanged;
_FillColor = value;
if (_FillColor != null)
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
OnGaugeItemChanged();
}
}
#endregion
#region LabelColor
/// <summary>
/// Gets or sets the Section Label Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the Section Label Color.")]
public Color LabelColor
{
get { return (_LabelColor); }
set
{
if (_LabelColor != value)
{
_LabelColor = value;
OnGaugeItemChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeLabelColor()
{
return (_LabelColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetLabelColor()
{
LabelColor = Color.Empty;
}
#endregion
#region MajorTickMarkFillColor
/// <summary>
/// Gets or sets the MajorTickMark Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the MajorTickMark Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor MajorTickMarkFillColor
{
get
{
if (_MajorTickMarkFillColor == null)
{
_MajorTickMarkFillColor = new GradientFillColor();
_MajorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
}
return (_MajorTickMarkFillColor);
}
set
{
if (_MajorTickMarkFillColor != null)
_MajorTickMarkFillColor.ColorTableChanged -= TickMarkFillColor_ColorTableChanged;
_MajorTickMarkFillColor = value;
if (_MajorTickMarkFillColor != null)
_MajorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region MinorTickMarkFillColor
/// <summary>
/// Gets or sets the MinorTickMark Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the MinorTickMark Fill Color.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public GradientFillColor MinorTickMarkFillColor
{
get
{
if (_MinorTickMarkFillColor == null)
{
_MinorTickMarkFillColor = new GradientFillColor();
_MinorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
}
return (_MinorTickMarkFillColor);
}
set
{
if (_MinorTickMarkFillColor != null)
_MinorTickMarkFillColor.ColorTableChanged -= TickMarkFillColor_ColorTableChanged;
_MinorTickMarkFillColor = value;
if (_MinorTickMarkFillColor != null)
_MinorTickMarkFillColor.ColorTableChanged += TickMarkFillColor_ColorTableChanged;
OnGaugeItemChanged(true);
}
}
#endregion
#region Scale
/// <summary>
/// Gets the associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GaugeScale Scale
{
get { return (_Scale); }
internal set { _Scale = value; }
}
#endregion
#region ScaleOffset
/// <summary>
/// Gets or sets the distance from the Scale, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the distance from the Scale, measured as a percentage.")]
public float ScaleOffset
{
get { return (_ScaleOffset); }
set
{
if (_ScaleOffset != value)
{
if (value < -1 || value > 1)
throw new ArgumentException("Scale Offset must be bwtween -1 and +1");
_ScaleOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#region StartValue
/// <summary>
/// Gets or sets the Starting value for the area
/// </summary>
[Browsable(true), Category("Layout"), DefaultValue(double.NaN)]
[Description("Indicates the Starting value for the area.")]
public double StartValue
{
get { return (_StartValue); }
set
{
if (_StartValue != value)
{
_StartValue = value;
OnStripCoverChanged();
}
}
}
private void OnStripCoverChanged()
{
if (StripCoverChanged != null)
StripCoverChanged(this, EventArgs.Empty);
OnGaugeItemChanged(true);
}
#endregion
#region Visible
/// <summary>
/// Gets or sets the item Visibility state.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(true)]
[Description("Indicates the item Visibility state.")]
[ParenthesizePropertyName(true)]
public override bool Visible
{
get { return (base.Visible); }
set
{
if (base.Visible != value)
{
base.Visible = value;
OnStripCoverChanged();
}
}
}
#endregion
#endregion
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region HasCapFillColor
internal bool HasCapFillColor
{
get { return (_CapFillColor != null && _CapFillColor.IsEmpty == false); }
}
#endregion
#region HasMajorTickMarkFillColor
internal bool HasMajorTickMarkFillColor
{
get { return (_MajorTickMarkFillColor != null &&
_MajorTickMarkFillColor.IsEmpty == false); }
}
#endregion
#region HasMinorTickMarkFillColor
internal bool HasMinorTickMarkFillColor
{
get { return (_MinorTickMarkFillColor != null && _MinorTickMarkFillColor.IsEmpty == false); }
}
#endregion
#region HasPointerFillColor
internal bool HasPointerFillColor
{
get { return (_PointerFillColor != null && _PointerFillColor.IsEmpty == false); }
}
#endregion
#region MaxValue
internal double MaxValue
{
get { return (_MaxValue); }
set { _MaxValue = value; }
}
#endregion
#region MinValue
internal double MinValue
{
get { return (_MinValue); }
set { _MinValue = value; }
}
#endregion
#region StartAngle
internal float StartAngle
{
get { return (_StartAngle); }
}
#endregion
#region StripePath
internal GraphicsPath StripePath
{
get { return (_StripePath); }
set
{
if (_StripePath != value)
{
if (_StripePath != null)
_StripePath.Dispose();
_StripePath = value;
}
}
}
#endregion
#region SweepAngle
internal float SweepAngle
{
get { return (_SweepAngle); }
}
#endregion
#endregion
#region Event processing
void FillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
void TickMarkFillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
void PointerFillColor_ColorTableChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcStripMetrics();
_Scale.NeedTickMarkRecalcLayout = true;
_Scale.NeedPointerRecalcLayout = true;
StripePath = null;
}
}
#region CalcStripMetrics
private void CalcStripMetrics()
{
_MinValue = (_StartValue.Equals(double.NaN) ? _Scale.MinValue : _StartValue);
_MaxValue = (_EndValue.Equals(double.NaN) ? _Scale.MaxValue : _EndValue);
if (_MinValue > _Scale.MaxValue)
_MinValue = _Scale.MaxValue;
_MinValue -= _Scale.MinValue;
if (_MinValue < 0)
_MinValue = 0;
if (_MaxValue < _Scale.MinValue)
_MaxValue = _Scale.MinValue;
_MaxValue -= _Scale.MinValue;
if (_MaxValue > _Scale.MaxValue - _Scale.MinValue)
_MaxValue = _Scale.MaxValue - _Scale.MinValue;
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
float spread = (float)Math.Abs(scale.MaxValue - scale.MinValue);
if (spread == 0)
spread = 1;
float dv = scale.SweepAngle / spread;
_StartAngle = (float)(dv * _MinValue) + scale.StartAngle;
_SweepAngle = (float)(dv * (_MaxValue - _MinValue));
if (scale.Reversed == true)
{
_StartAngle = (scale.StartAngle + scale.SweepAngle) - (_StartAngle - scale.StartAngle);
_SweepAngle = -_SweepAngle;
}
}
#endregion
#endregion
#endregion
#region GetPoint
protected PointF GetPoint(float radius, float angle)
{
PointF pt = new PointF();
// Normalize the angle and calculate some
// working vars
if (angle < 0)
angle += 360;
angle = angle % 360;
// Determine the angle quadrant, and then calculate
// the intersecting coordinate accordingly
double radians = GetRadians(angle % 90);
if (angle < 90)
{
pt.X = (float)(Math.Cos(radians) * radius);
pt.Y = (float)(Math.Sin(radians) * radius);
}
else if (angle < 180)
{
pt.X = -(float)(Math.Sin(radians) * radius);
pt.Y = (float)(Math.Cos(radians) * radius);
}
else if (angle < 270)
{
pt.X = -(float)(Math.Cos(radians) * radius);
pt.Y = -(float)(Math.Sin(radians) * radius);
}
else
{
pt.X = (float)(Math.Sin(radians) * radius);
pt.Y = -(float)(Math.Cos(radians) * radius);
}
pt.X += _Scale.Center.X;
pt.Y += _Scale.Center.Y;
return (pt);
}
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
protected double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region ValueInRange
internal bool ValueInRange(double value)
{
RecalcLayout();
double startValue = (_StartValue.Equals(double.NaN) ? MinValue : _StartValue);
double endValue = (_EndValue.Equals(double.NaN) ? MaxValue : _EndValue);
if (startValue > endValue)
{
double temp = startValue;
startValue = endValue;
endValue = temp;
}
return (value >= startValue && value <= endValue);
}
#endregion
#region ProcessTemplateText
protected override void ProcessTemplateText(
GaugeControl gauge, StringBuilder sb, string key, string data)
{
switch (key)
{
case "StartValue":
sb.Append(string.IsNullOrEmpty(data)
? _StartValue.ToString()
: String.Format("{0:" + data + "}", _StartValue));
break;
case "EndValue":
sb.Append(string.IsNullOrEmpty(data)
? _EndValue.ToString()
: String.Format("{0:" + data + "}", _EndValue));
break;
default:
base.ProcessTemplateText(gauge, sb, key, data);
break;
}
}
#endregion
#region IDisposable Members
void IDisposable.Dispose()
{
StripePath = null;
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeStrip copy = new GaugeStrip();
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeStrip c = copy as GaugeStrip;
if (c != null)
{
base.CopyToItem(c);
if (_CapFillColor != null)
c.CapFillColor = (GradientFillColor)_CapFillColor.Clone();
c.EndValue = _EndValue;
if (_PointerFillColor != null)
c.PointerFillColor = (GradientFillColor)_PointerFillColor.Clone();
if (_FillColor != null)
c.FillColor = (GradientFillColor)_FillColor.Clone();
c.LabelColor = _LabelColor;
if (_MajorTickMarkFillColor != null)
c.MajorTickMarkFillColor = (GradientFillColor)_MajorTickMarkFillColor.Clone();
if (_MinorTickMarkFillColor != null)
c.MinorTickMarkFillColor = (GradientFillColor)_MinorTickMarkFillColor.Clone();
c.ScaleOffset = _ScaleOffset;
c.StartValue = _StartValue;
}
}
#endregion
}
}

View File

@@ -0,0 +1,327 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugeTickMarkConvertor))]
public class GaugeTickMark : GaugeTickMarkBase
{
#region Private variables
private double _Interval;
private double _IntervalOffset;
private double _DefaultInterval;
private TickPoint[] _TickPoints;
#endregion
public GaugeTickMark(GaugeScale scale, GaugeTickMarkRank rank,
GaugeMarkerStyle style, float width, float length, double interval)
: base(scale, rank, style, width, length)
{
_Interval = interval;
_DefaultInterval = interval;
}
#region Public properties
#region Interval
/// <summary>
/// Gets or sets the TickMark Interval spacing
/// </summary>
[Browsable(true)]
[Category("Layout")]
[Description("Indicates the TickMark Interval spacing.")]
public double Interval
{
get { return (_Interval); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_Interval != value)
{
_Interval = value;
OnGaugeItemChanged(true);
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeInterval()
{
return (_Interval != _DefaultInterval);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetInterval()
{
Interval = _DefaultInterval;
}
#endregion
#region IntervalOffset
/// <summary>
/// Gets or sets the initial TickMark Interval Offset
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0d)]
[Description("Indicates the initial TickMark Interval Offset.")]
public double IntervalOffset
{
get { return (_IntervalOffset); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_IntervalOffset != value)
{
_IntervalOffset = value;
OnGaugeItemChanged(true);
}
}
}
#endregion
#endregion
#region Internal properties
#region TickPoints
internal TickPoint[] TickPoints
{
get { return (_TickPoints); }
set { _TickPoints = value; }
}
#endregion
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcTickPoints();
Scale.NeedLabelRecalcLayout = true;
}
}
#region CalcTickPoints
private void CalcTickPoints()
{
_TickPoints = null;
if (_Interval > 0)
{
double ticks = Scale.MaxValue - Scale.MinValue;
if (ticks > 0)
{
int n = (int) ((ticks - _IntervalOffset)/_Interval) + 1;
if (n > 0)
{
if (Scale is GaugeCircularScale)
CalcCircularTickPoints(Scale as GaugeCircularScale, ticks, n);
else if (Scale is GaugeLinearScale)
CalcLinearTickPoints(Scale as GaugeLinearScale, ticks, n);
}
}
}
}
#region CalcCircularTickPoints
private void CalcCircularTickPoints(
GaugeCircularScale scale, double ticks, int n)
{
double dpt = scale.SweepAngle / ticks;
double theta = _Interval * dpt;
double startAngle = scale.StartAngle;
if (scale.Reversed == true)
startAngle += scale.SweepAngle;
int dir = scale.Reversed ? -1 : 1;
startAngle += (dpt * _IntervalOffset * dir);
_TickPoints = new TickPoint[n];
double interval = _IntervalOffset;
for (int i = 0; i < n; i++)
{
_TickPoints[i] = new TickPoint(this);
_TickPoints[i].Angle = (float)(startAngle + (i * theta * dir));
_TickPoints[i].Point = scale.GetPoint(Radius, _TickPoints[i].Angle);
_TickPoints[i].Interval = interval;
interval += _Interval;
}
}
#endregion
#region CalcLinearTickPoints
private void CalcLinearTickPoints(
GaugeLinearScale scale, double ticks, int n)
{
double dpt = scale.AbsScaleLength/ticks;
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalTickPoints(n, dpt);
else
CalcVerticalTickPoints(n, dpt);
}
#region CalcHorizontalTickPoints
private void CalcHorizontalTickPoints(int n, double dpt)
{
_TickPoints = new TickPoint[n];
double interval = _IntervalOffset;
for (int i = 0; i < n; i++)
{
_TickPoints[i] = new TickPoint(this);
int x = (Scale.Reversed == true)
? Bounds.Right - (int)(dpt * interval)
: Bounds.X + (int)(dpt * interval);
_TickPoints[i].Point = new Point(x, Bounds.Y);
_TickPoints[i].Interval = interval;
interval += _Interval;
}
}
#endregion
#region CalcVerticalTickPoints
private void CalcVerticalTickPoints(int n, double dpt)
{
_TickPoints = new TickPoint[n];
double interval = _IntervalOffset;
for (int i = 0; i < n; i++)
{
_TickPoints[i] = new TickPoint(this);
int y = (Scale.Reversed == true)
? Bounds.Top + (int)(dpt * interval)
: Bounds.Bottom - (int)(dpt * interval);
_TickPoints[i].Point = new Point(Bounds.X, y);
_TickPoints[i].Interval = interval;
interval += _Interval;
}
}
#endregion
#endregion
#endregion
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeTickMark copy = new
GaugeTickMark(Scale, Rank, Layout.Style, Width, Length, Interval);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeTickMark c = copy as GaugeTickMark;
if (c != null)
{
base.CopyToItem(c);
c.Interval = _Interval;
c.IntervalOffset = _IntervalOffset;
c._DefaultInterval = _DefaultInterval;
}
}
#endregion
}
#region GaugeTickMarkConvertor
public class GaugeTickMarkConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeTickMark tickMark = value as GaugeTickMark;
if (tickMark != null)
{
//ColorConverter cvt = new ColorConverter();
//if (lct.Start != Color.Empty)
// return (cvt.ConvertToString(lct.Start));
//if (lct.End != Color.Empty)
// return (cvt.ConvertToString(lct.End));
//if (lct.GradientAngle != 90)
// return (lct.GradientAngle.ToString());
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,596 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugeTickMarkBaseConvertor))]
public class GaugeTickMarkBase : GaugeItem
{
#region Private variables
private int _Radius;
private int _Width;
private int _Length;
private int _Offset;
private Rectangle _Bounds;
private TickMarkLayout _Layout;
private GaugeTickMarkRank _Rank;
private GaugeMarker _GaugeMarker;
private GaugeScale _Scale;
#endregion
public GaugeTickMarkBase(GaugeScale scale,
GaugeTickMarkRank rank, GaugeMarkerStyle style, float width, float length)
: this(scale, rank, new TickMarkLayout(style, width, length))
{
}
public GaugeTickMarkBase(GaugeScale scale, GaugeTickMarkRank rank, TickMarkLayout layout)
{
_Scale = scale;
_Rank = rank;
_Layout = layout;
_GaugeMarker = new GaugeMarker();
HookEvents(true);
}
#region Hidden properties
#region Name
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new string Name
{
get { return (base.Name); }
set { base.Name = value; }
}
#endregion
#region Tooltip
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new string Tooltip
{
get { return (base.Tooltip); }
set { base.Tooltip = value; }
}
#endregion
#endregion
#region Public properties
#region Scale
/// <summary>
/// Gets the associated Scale
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public GaugeScale Scale
{
get { return (_Scale); }
internal set { _Scale = value; }
}
#endregion
#region Layout
/// <summary>
/// Gets the Tickmark leyout
/// </summary>
[Browsable(true), Category("Layout")]
[Description("Specifies the TickMark layout properties.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public TickMarkLayout Layout
{
get { return (_Layout); }
}
#endregion
#region Visible
public override bool Visible
{
get { return (base.Visible); }
set
{
if (base.Visible != value)
{
base.Visible = value;
if (_Scale != null)
_Scale.Labels.NeedRecalcLayout = true;
}
}
}
#endregion
#endregion
#region Internal properties
#region Bounds
internal Rectangle Bounds
{
get { return (_Bounds); }
set { _Bounds = value; }
}
#endregion
#region Length
internal int Length
{
get { return (_Length); }
set { _Length = value; }
}
#endregion
#region Offset
internal int Offset
{
get { return (_Offset); }
set { _Offset = value; }
}
#endregion
#region Radius
internal int Radius
{
get { return (_Radius); }
}
#endregion
#region Rank
internal GaugeTickMarkRank Rank
{
get { return (_Rank); }
}
#endregion
#region Width
internal int Width
{
get { return (_Width); }
set { _Width = value; }
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
{
_Layout.TickMarkLayoutChanged += TickMarkLayout_TickMarkLayoutChanged;
}
else
{
_Layout.TickMarkLayoutChanged -= TickMarkLayout_TickMarkLayoutChanged;
}
}
#endregion
#region Event processing
void TickMarkLayout_TickMarkLayoutChanged(object sender, EventArgs e)
{
OnGaugeItemChanged(true);
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcTickMarkMetrics();
_GaugeMarker.Clear();
}
}
#region CalcTickMarkMetrics
private void CalcTickMarkMetrics()
{
if (Scale is GaugeCircularScale)
CalcCircularMetrics(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearMetrics(Scale as GaugeLinearScale);
}
#region CalcCircularMetrics
private void CalcCircularMetrics(GaugeCircularScale scale)
{
_Radius = scale.AbsRadius;
_Length = (int)(_Radius * _Layout.Length);
_Width = (int)(_Radius * _Layout.Width);
int m = scale.AbsScaleWidth;
int offset = (int)(scale.AbsRadius * _Layout.ScaleOffset);
switch (_Layout.Placement)
{
case DisplayPlacement.Near:
_Radius -= ((_Length + m / 2) + offset);
break;
case DisplayPlacement.Center:
_Radius += ((_Length / 2) + offset + 1);
break;
case DisplayPlacement.Far:
_Radius += ((_Length + m / 2) + offset);
break;
}
}
#endregion
#region CalcLinearMetrics
private void CalcLinearMetrics(GaugeLinearScale scale)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalLayout(scale);
else
CalcVerticalLayout(scale);
}
#region CalcHorizontalLayout
private void CalcHorizontalLayout(GaugeLinearScale scale)
{
int n = scale.AbsWidth;
_Length = (int)(n * _Layout.Length);
_Width = (int)(n * _Layout.Width);
if (_Layout.Length > 0 && _Length < 2)
_Length = 2;
if (_Layout.Width > 0 && _Width < 2)
_Width = 2;
int offset = (int) (n * _Layout.ScaleOffset);
_Bounds = scale.ScaleBounds;
_Bounds.Height = _Length;
switch (_Layout.Placement)
{
case DisplayPlacement.Near:
_Bounds.Y = scale.ScaleBounds.Top - _Length - offset;
break;
case DisplayPlacement.Center:
_Bounds.Y = scale.Center.Y - _Length / 2 - offset;
break;
case DisplayPlacement.Far:
_Bounds.Y = scale.ScaleBounds.Bottom + offset;
break;
}
_Offset = _Bounds.Y - scale.ScaleBounds.Y;
}
#endregion
#region CalcVerticalLayout
private void CalcVerticalLayout(GaugeLinearScale scale)
{
int n = scale.AbsWidth;
_Length = (int)(n * _Layout.Length);
_Width = (int)(n * _Layout.Width);
if (_Layout.Length > 0 && _Length < 2)
_Length = 2;
if (_Layout.Width > 0 && _Width < 2)
_Width = 2;
int offset = (int)(n * _Layout.ScaleOffset);
_Bounds = scale.ScaleBounds;
_Bounds.Width = _Length;
switch (_Layout.Placement)
{
case DisplayPlacement.Near:
_Bounds.X = scale.ScaleBounds.Left - _Length - offset;
break;
case DisplayPlacement.Center:
_Bounds.X = scale.Center.X - _Length / 2 - offset;
break;
case DisplayPlacement.Far:
_Bounds.X = scale.ScaleBounds.Right + offset;
break;
}
_Offset = _Bounds.X - scale.ScaleBounds.X;
}
#endregion
#endregion
#endregion
#endregion
#region Paint support
#region PaintTickPoint
#region PaintTickPoint
internal void PaintTickPoint(Graphics g, TickPoint tp)
{
Image image = _Layout.Image ?? GetTickMarkBitmap(g, tp);
if (image != null)
{
if (Scale is GaugeCircularScale)
PaintCircularTickPoint(g, tp, image);
else if (Scale is GaugeLinearScale)
PaintLinearTickPoint(g, tp, image, Scale as GaugeLinearScale);
}
}
#endregion
#region PaintCircularTickPoint
private void PaintCircularTickPoint(Graphics g, TickPoint tp, Image image)
{
Rectangle r = new Rectangle(0, 0, _Width, _Length);
float angle = tp.Angle + 90;
if (_Layout.Placement == DisplayPlacement.Near)
angle += 180;
g.TranslateTransform(tp.Point.X, tp.Point.Y);
g.RotateTransform(angle % 360);
r.X -= _Width / 2;
g.DrawImage(image, r);
g.ResetTransform();
}
#endregion
#region PaintLinearTickPoint
private void PaintLinearTickPoint(Graphics g,
TickPoint tp, Image image, GaugeLinearScale scale)
{
if (scale.Orientation == Orientation.Horizontal)
PaintHorizontalTickPoint(g, tp, image);
else
PaintVerticalTickPoint(g, tp, image);
}
#region PaintHorizontalTickPoint
private void PaintHorizontalTickPoint(Graphics g, TickPoint tp, Image image)
{
if (_Layout.Placement != DisplayPlacement.Far)
{
Rectangle r = new Rectangle(tp.Point.X, tp.Point.Y, _Width, _Length);
r.X -= _Width / 2;
g.DrawImage(image, r);
}
else
{
Rectangle r = new Rectangle(0, 0, _Width, _Length);
g.TranslateTransform(tp.Point.X, tp.Point.Y + _Length - (_Length % 2));
g.RotateTransform(180);
r.X -= _Width / 2;
g.DrawImage(image, r);
g.ResetTransform();
}
}
#endregion
#region PaintVerticalTickPoint
private void PaintVerticalTickPoint(Graphics g, TickPoint tp, Image image)
{
Rectangle r = new Rectangle(0, 0, _Width, _Length);
if (_Layout.Placement == DisplayPlacement.Far)
{
g.TranslateTransform(tp.Point.X + _Length - (_Length % 2), tp.Point.Y);
g.RotateTransform(90);
}
else
{
g.TranslateTransform(tp.Point.X, tp.Point.Y);
g.RotateTransform(-90);
}
r.X -= (_Width / 2);
g.DrawImage(image, r);
g.ResetTransform();
}
#endregion
#endregion
#endregion
#region GetTickMarkBitmap
internal Bitmap GetTickMarkBitmap(Graphics g, TickPoint tp)
{
if (_Layout.Style != GaugeMarkerStyle.None)
{
if (_Width > 0 && _Length > 0)
{
return (_GaugeMarker.GetMarkerBitmap(g, _Layout.Style,
GetTickMarkFillColor(tp), _Width, _Length));
}
}
return (null);
}
#endregion
#region GetTickMarkFillColor
private GradientFillColor GetTickMarkFillColor(TickPoint tp)
{
if (_Rank == GaugeTickMarkRank.Custom)
return (Layout.FillColor);
ColorSourceFillEntry entry = (_Rank == GaugeTickMarkRank.Major)
? ColorSourceFillEntry.MajorTickMark : ColorSourceFillEntry.MinorTickMark;
GradientFillColor fillColor = (Scale.GetRangeFillColor(tp.Interval, entry) ??
Scale.GetSectionFillColor(tp.Interval, entry)) ?? Layout.FillColor;
return (fillColor);
}
#endregion
#endregion
#region OnDispose
protected override void OnDispose()
{
HookEvents(false);
_GaugeMarker.Dispose();
base.OnDispose();
}
#endregion
#region ICloneable Members
public override object Clone()
{
GaugeTickMarkBase copy = new GaugeTickMarkBase(
_Scale, _Rank, _Layout.Style, _Layout.Width, _Layout.Length);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
public override void CopyToItem(GaugeItem copy)
{
GaugeTickMarkBase c = copy as GaugeTickMarkBase;
if (c != null)
{
base.CopyToItem(c);
_Layout.CopyToItem(c.Layout);
}
}
#endregion
}
#region GaugeTickMarkBaseConvertor
public class GaugeTickMarkBaseConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeTickMarkBase tickMark = value as GaugeTickMarkBase;
if (tickMark != null)
{
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
#region Enums
public enum GaugeTickMarkRank
{
Major,
Minor,
Custom
}
public enum GaugeTickMarkOverlap
{
ReplaceNone,
ReplaceLast,
ReplaceAll
}
#endregion
}

View File

@@ -0,0 +1,171 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using System.Windows.Forms;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(GaugeTickMarkLabelConvertor))]
public class GaugeTickMarkLabel : GaugeTickMarkBase
{
#region Private properties
private TickPoint _TickPoint;
private double _Interval;
#endregion
public GaugeTickMarkLabel(GaugeScale scale, GaugeTickMarkRank rank,
GaugeMarkerStyle style, float width, float length, double interval)
: base(scale, rank, style, width, length)
{
_Interval = interval;
}
#region Internal properties
internal double Interval
{
get { return (_Interval); }
set { _Interval = value; }
}
internal TickPoint TickPoint
{
get { return (_TickPoint); }
set { _TickPoint = value; }
}
#endregion
#region RecalcLayout
public override void RecalcLayout()
{
if (NeedRecalcLayout == true)
{
base.RecalcLayout();
CalcTickPoint();
}
}
#region CalcTickPoint
private void CalcTickPoint()
{
_TickPoint = null;
if (Scale is GaugeCircularScale)
CalcCircularTickPoint(Scale as GaugeCircularScale);
else if (Scale is GaugeLinearScale)
CalcLinearTickPoint(Scale as GaugeLinearScale);
}
#region CalcCircularTickPoint
private void CalcCircularTickPoint(GaugeCircularScale scale)
{
double spread = Scale.MaxValue - Scale.MinValue;
double dpt = scale.SweepAngle / spread;
if (_Interval >= 0 && _Interval <= spread)
{
_TickPoint = new TickPoint(this);
if (scale.Reversed == true)
_TickPoint.Angle = (float)(scale.StartAngle + scale.SweepAngle - (_Interval * dpt));
else
_TickPoint.Angle = (float)(scale.StartAngle + _Interval * dpt);
_TickPoint.Point = scale.GetPoint(Radius, _TickPoint.Angle);
_TickPoint.Interval = _Interval;
}
}
#endregion
#region CalcLinearTickPoint
private void CalcLinearTickPoint(GaugeLinearScale scale)
{
double spread = Math.Abs(scale.MaxValue - scale.MinValue);
double dpt = scale.AbsScaleLength / spread;
if (_Interval >= 0 && _Interval <= spread)
{
if (scale.Orientation == Orientation.Horizontal)
CalcHorizontalTickPoint(scale, dpt);
else
CalcVerticalTickPoint(scale, dpt);
}
}
#region CalcHorizontalTickPoint
private void CalcHorizontalTickPoint(GaugeLinearScale scale, double dpt)
{
_TickPoint = new TickPoint(this);
int x = (scale.Reversed == true)
? Scale.Bounds.Right - (int)(dpt * _Interval)
: Scale.Bounds.X + (int)(dpt * _Interval);
int y = scale.ScaleBounds.Y + Offset;
_TickPoint.Point = new Point(x, y);
_TickPoint.Interval = _Interval;
}
#endregion
#region CalcVerticalTickPoint
private void CalcVerticalTickPoint(GaugeLinearScale scale, double dpt)
{
_TickPoint = new TickPoint(this);
int x = scale.ScaleBounds.X + Offset;
int y = (scale.Reversed == true)
? Scale.Bounds.Top + (int)(dpt * _Interval)
: Scale.Bounds.Bottom - (int)(dpt * _Interval);
_TickPoint.Point = new Point(x, y);
_TickPoint.Interval = _Interval;
}
#endregion
#endregion
#endregion
#endregion
}
#region GaugeLabelTickMarkConvertor
public class GaugeTickMarkLabelConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
GaugeTickMarkLabel tickMark = value as GaugeTickMarkLabel;
if (tickMark != null)
{
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,456 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Globalization;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(TickMarkLayoutConvertor))]
public class TickMarkLayout : IDisposable, ICloneable
{
#region Events
public event EventHandler<EventArgs> TickMarkLayoutChanged;
#endregion
#region Private variables
private GaugeMarkerStyle _Style;
private DisplayPlacement _Placement;
private float _ScaleOffset;
private float _Width;
private float _Length;
private GradientFillColor _FillColor;
private GaugeTickMarkOverlap _Overlap;
private Image _Image;
private Bitmap _Bitmap;
private float _DefaultWidth;
private float _DefaultLength;
private GaugeMarkerStyle _DefaultStyle;
#endregion
public TickMarkLayout()
: this(GaugeMarkerStyle.Rectangle, .045f, .09f)
{
}
public TickMarkLayout(GaugeMarkerStyle style, float width, float length)
{
_Style = style;
_Width = width;
_Length = length;
_DefaultStyle = style;
_DefaultWidth = width;
_DefaultLength = length;
_Placement = DisplayPlacement.Center;
FillColor = new GradientFillColor(Color.DarkGray, Color.White);
FillColor.BorderColor = Color.DimGray;
FillColor.BorderWidth = 1;
_Overlap = GaugeTickMarkOverlap.ReplaceAll;
}
#region Public properties
#region FillColor
/// <summary>
/// Gets or sets the TickMark Fill Color
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the TickMark Fill Color.")]
public GradientFillColor FillColor
{
get
{
if (_FillColor == null)
{
_FillColor = new GradientFillColor();
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
}
return (_FillColor);
}
set
{
if (_FillColor != null)
_FillColor.ColorTableChanged -= FillColor_ColorTableChanged;
_FillColor = value;
if (_FillColor != null)
_FillColor.ColorTableChanged += FillColor_ColorTableChanged;
OnTickMarkLayoutChanged();
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal bool ShouldSerializeFillColor()
{
return (_FillColor.IsEqualTo(Color.DarkGray,
Color.White, 90, GradientFillType.Auto, Color.DimGray, 1) == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal void ResetFillColor()
{
FillColor = new GradientFillColor(Color.DarkGray, Color.White);
FillColor.BorderColor = Color.DimGray;
FillColor.BorderWidth = 1;
}
#endregion
#region Image
/// <summary>
/// Gets or sets the Image to use for the TickMark
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(null)]
[Description("Indicates the Image to use for the TickMark.")]
public Image Image
{
get { return (_Image); }
set
{
if (_Image != value)
{
_Image = value;
OnTickMarkLayoutChanged();
}
}
}
#endregion
#region Length
/// <summary>
/// Gets or sets the Length of the TickMark, specified as a percentage
/// </summary>
[Browsable(true), Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.RangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Length of the TickMark, specified as a percentage.")]
public float Length
{
get { return (_Length); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_Length != value)
{
_Length = value;
OnTickMarkLayoutChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeLength()
{
return (_Length != _DefaultLength);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetLength()
{
Length = _DefaultLength;
}
#endregion
#region Placement
/// <summary>
/// Gets or sets the Placement of the TickMarks with respect to the Scale
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(DisplayPlacement.Center)]
[Description("Indicates the Placement of the TickMarks with respect to the Scale.")]
public DisplayPlacement Placement
{
get { return (_Placement); }
set
{
if (_Placement != value)
{
_Placement = value;
OnTickMarkLayoutChanged();
}
}
}
#endregion
#region ScaleOffset
/// <summary>
/// Gets or sets the distance from the TickMark to the Scale, measured as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout"), DefaultValue(0f)]
[Editor("DevComponents.Instrumentation.Design.OffsetRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the distance from the TickMark to the Scale, measured as a percentage.")]
public float ScaleOffset
{
get { return (_ScaleOffset); }
set
{
if (_ScaleOffset != value)
{
_ScaleOffset = value;
OnTickMarkLayoutChanged();
}
}
}
#endregion
#region Style
/// <summary>
/// Gets or sets the TickMark Style
/// </summary>
[Browsable(true), Category("Appearance")]
[Description("Indicates the TickMark Style.")]
public GaugeMarkerStyle Style
{
get { return (_Style); }
set
{
if (_Style != value)
{
_Style = value;
OnTickMarkLayoutChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeStyle()
{
return (_Style != _DefaultStyle);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetStyle()
{
Style = _DefaultStyle;
}
#endregion
#region Overlap
/// <summary>
/// Gets or sets how the TickMark overlaps previous TickMarks
/// </summary>
[Browsable(true)]
[Category("Behavior"), DefaultValue(GaugeTickMarkOverlap.ReplaceAll)]
[Description("Indicates how the TickMark overlaps previous TickMarks.")]
public GaugeTickMarkOverlap Overlap
{
get { return (_Overlap); }
set
{
if (_Overlap != value)
{
_Overlap = value;
OnTickMarkLayoutChanged();
}
}
}
#endregion
#region Width
/// <summary>
/// Gets or sets the Width of the TickMark, specified as a percentage
/// </summary>
[Browsable(true)]
[Category("Layout")]
[Editor("DevComponents.Instrumentation.Design.WidthRangeValueEditor, DevComponents.Instrumentation.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=76cb4c6eb576bca5", typeof(UITypeEditor))]
[Description("Indicates the Width of the TickMark, specified as a percentage.")]
public float Width
{
get { return (_Width); }
set
{
if (value < 0)
throw new ArgumentException("Value can not be less than zero.");
if (_Width != value)
{
_Width = value;
OnTickMarkLayoutChanged();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeWidth()
{
return (_Width != _DefaultWidth);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetWidth()
{
Width = _DefaultWidth;
}
#endregion
#endregion
#region Internal properties
#region Bitmap
internal Bitmap Bitmap
{
get { return (_Bitmap); }
set
{
if (_Bitmap != null)
_Bitmap.Dispose();
_Bitmap = value;
}
}
#endregion
#endregion
#region HookEvents
private void HookEvents(bool hook)
{
if (hook == true)
{
}
else
{
if (_FillColor != null)
_FillColor.ColorTableChanged -= FillColor_ColorTableChanged;
}
}
#endregion
#region Event processing
void FillColor_ColorTableChanged(object sender, EventArgs e)
{
OnTickMarkLayoutChanged();
}
#endregion
#region OnTickMarkLayoutChanged
protected virtual void OnTickMarkLayoutChanged()
{
if (TickMarkLayoutChanged != null)
TickMarkLayoutChanged(this, EventArgs.Empty);
}
#endregion
#region IDisposable Members
public void Dispose()
{
HookEvents(false);
}
#endregion
#region ICloneable Members
public virtual object Clone()
{
TickMarkLayout copy = new
TickMarkLayout(_Style, _Width, _Length);
CopyToItem(copy);
return (copy);
}
#endregion
#region CopyToItem
internal virtual void CopyToItem(TickMarkLayout copy)
{
if (_FillColor != null)
copy.FillColor = (GradientFillColor) _FillColor.Clone();
copy.Image = _Image;
copy.Length = _Length;
copy.Placement = _Placement;
copy.ScaleOffset = _ScaleOffset;
copy.Style = _Style;
copy.Overlap = _Overlap;
copy.Width = _Width;
}
#endregion
}
#region TickMarkLayoutConvertor
public class TickMarkLayoutConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
TickMarkLayout layout = value as TickMarkLayout;
if (layout != null)
{
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
}

View File

@@ -0,0 +1,95 @@
using System;
using System.Drawing;
namespace DevComponents.Instrumentation
{
internal class TickPoint : ICloneable
{
#region Private variables
private Point _Point;
private float _Angle;
private double _Interval;
private GaugeTickMarkBase _TickMark;
private bool _Visible = true;
#endregion
public TickPoint(GaugeTickMarkBase tickMark)
{
_TickMark = tickMark;
}
#region Public properties
#region Angle
public float Angle
{
get { return (_Angle); }
set { _Angle = value; }
}
#endregion
#region Point
public Point Point
{
get { return (_Point); }
set { _Point = value; }
}
#endregion
#region Interval
public double Interval
{
get { return (_Interval); }
set { _Interval = value; }
}
#endregion
#region TickMark
public GaugeTickMarkBase TickMark
{
get { return (_TickMark); }
set { _TickMark = value; }
}
#endregion
#region Visible
public bool Visible
{
get { return (_Visible); }
set { _Visible = value; }
}
#endregion
#endregion
#region ICloneable Members
public object Clone()
{
TickPoint tp = new TickPoint(_TickMark);
tp.Point = _Point;
tp.Angle = _Angle;
tp.Interval = _Interval;
tp.Visible = _Visible;
return (tp);
}
#endregion
}
}

View File

@@ -0,0 +1,147 @@
using System;
using System.Drawing;
namespace DevComponents.Instrumentation
{
internal class Licensing
{
#if !TRIAL
internal static bool KeyValidated;
internal static int KeyValidated2;
internal static bool ValidateLicenseKey(string key)
{
string[] parts = key.Split('-');
int i = 10;
foreach (string s in parts)
{
if (s == "88405280")
i++;
else if (s == "D06E")
i += 10;
else if (s == "4617")
i += 8;
else if (s == "8810")
i += 12;
else if (s == "64462F60FA93")
i += 3;
}
if (i == 29)
return true;
KeyValidated = true;
return (false);
}
internal static bool CheckLicenseKey(string key)
{
// {F962CEC7-CD8F-4911-A9E9-CAB39962FC1F}, 114
string[] parts = key.Split('-');
int test = 0;
for (int i = parts.Length - 1; i >= 0; i--)
{
if (parts[i] == "CD8F")
test += 12;
else if (parts[i] == "CAB39962FC1F")
test += 2;
else if (parts[i] == "A9E9")
test += 3;
else if (parts[i] == "4911")
test += 7;
else if (parts[i] == "F962CEC7")
test += 13;
}
KeyValidated2 = test + 77;
if (test == 23)
return false;
return true;
}
#endif
#if TRIAL
private static Color m_ColorExpFlag = Color.Empty;
internal static int ColorCountExp;
internal static bool ColorExpAlt()
{
Color clr=SystemColors.Control;
Color clr2;
Color clr3;
clr2=clr;
if(clr2.ToArgb()==clr.ToArgb())
{
clr3=clr2;
}
else
{
clr3=clr;
}
ColorCountExp=clr.A;
if(!m_ColorExpFlag.IsEmpty)
{
return (m_ColorExpFlag==Color.Black?false:true);
}
try
{
Microsoft.Win32.RegistryKey key=Microsoft.Win32.Registry.ClassesRoot;
key=key.CreateSubKey("CLSID\\{542FD3B2-2F65-4290-AB4F-EBFF0444C54C}\\InprocServer32");
try
{
if(key.GetValue("")==null || key.GetValue("").ToString()=="")
{
key.SetValue("",DateTime.Today.ToOADate().ToString());
}
else
{
if(key.GetValue("").ToString()=="windows3.dll")
{
m_ColorExpFlag=Color.White;
key.Close();
key=null;
return true;
}
DateTime date=DateTime.FromOADate(double.Parse(key.GetValue("").ToString()));
if(((TimeSpan)DateTime.Today.Subtract(date)).TotalDays>30)
{
m_ColorExpFlag=Color.White;
key.SetValue("","windows3.dll");
key.Close();
key=null;
return true;
}
if(((TimeSpan)DateTime.Today.Subtract(date)).TotalDays<0)
{
m_ColorExpFlag=Color.White;
key.SetValue("","windows2.dll");
key.Close();
key=null;
return true;
}
}
}
finally
{
if(key!=null)
key.Close();
}
}
catch{}
m_ColorExpFlag=Color.Black;
return false;
}
#endif
}
}

View File

@@ -0,0 +1,108 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
namespace DevComponents.Instrumentation.Primitives
{
public class PointFConverter : ExpandableObjectConverter
{
#region CanConvertTo
public override bool CanConvertTo(
ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string))
return (true);
return (base.CanConvertTo(context, destinationType));
}
#endregion
#region ConvertTo
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
PointF pf = (PointF)value;
return (String.Format("{0:f}, {1:f}", pf.X, pf.Y));
}
return (base.ConvertTo(context, culture, value, destinationType));
}
#endregion
#region CanConvertFrom
public override bool CanConvertFrom(
ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
return (true);
return (base.CanConvertFrom(context, sourceType));
}
#endregion
#region ConvertFrom
public override object ConvertFrom(
ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (value is string)
{
string[] values = ((string)value).Split(',');
if (values.Length != 2)
throw new ArgumentException("Invalid value to convert.");
try
{
float x = float.Parse(values[0]);
float y = float.Parse(values[1]);
PointF pf = new PointF(x, y);
return (pf);
}
catch (Exception exp)
{
throw new ArgumentException("Invalid value to convert.");
}
}
return base.ConvertFrom(context, culture, value);
}
#endregion
#region GetCreateInstanceSupported
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
{
return (true);
}
#endregion
#region CreateInstance
public override object CreateInstance(
ITypeDescriptorContext context, IDictionary propertyValues)
{
if (propertyValues != null)
return (new PointF((float)propertyValues["X"], (float)propertyValues["Y"]));
return (null);
}
#endregion
}
}

View File

@@ -0,0 +1,285 @@
using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
namespace DevComponents
{
/// <summary>
/// Summary description for RemindForm.
/// </summary>
internal class RemindForm : Form
{
private Label label1;
private Label label2;
private Button button1;
private Button button2;
private Timer timer1;
private Label label3;
private Label label4;
private GroupBox groupBox1;
private Label label5;
private Label label6;
private LinkLabel linkOrder;
private Label label7;
private LinkLabel linkEmail;
private LinkLabel linkHome;
private IContainer components;
public RemindForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
label2.Text="(c) "+System.DateTime.Now.Year.ToString()+" by DevComponents, All Rights Reserved.";
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
static DateTime _LastShown = DateTime.MinValue;
public new void ShowDialog()
{
if (_LastShown != DateTime.MinValue)
{
if (_LastShown.Subtract(DateTime.Now).TotalMinutes < 15)
return;
}
_LastShown = DateTime.Now;
base.ShowDialog();
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.linkEmail = new System.Windows.Forms.LinkLabel();
this.label3 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.linkHome = new System.Windows.Forms.LinkLabel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label7 = new System.Windows.Forms.Label();
this.linkOrder = new System.Windows.Forms.LinkLabel();
this.label6 = new System.Windows.Forms.Label();
this.label5 = new System.Windows.Forms.Label();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.label1.Location = new System.Drawing.Point(12, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(252, 15);
this.label1.TabIndex = 0;
this.label1.Text = "DevComponents DotNetBar Component";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(10, 32);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(307, 13);
this.label2.TabIndex = 1;
this.label2.Text = "(c) 2001-2004 by DevComponents.com, All Rights Reserved";
//
// button1
//
this.button1.Enabled = false;
this.button1.Location = new System.Drawing.Point(10, 242);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 24);
this.button1.TabIndex = 0;
this.button1.Text = "OK";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(89, 242);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(72, 24);
this.button2.TabIndex = 3;
this.button2.Text = "Buy Now";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 800;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// linkEmail
//
this.linkEmail.Location = new System.Drawing.Point(52, 200);
this.linkEmail.Name = "linkEmail";
this.linkEmail.Size = new System.Drawing.Size(145, 16);
this.linkEmail.TabIndex = 4;
this.linkEmail.TabStop = true;
this.linkEmail.Text = "info@devcomponents.com";
this.linkEmail.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkEmail_LinkClicked);
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 201);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(40, 13);
this.label3.TabIndex = 5;
this.label3.Text = "E-Mail:";
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(13, 217);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(31, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Web:";
//
// linkHome
//
this.linkHome.Location = new System.Drawing.Point(53, 216);
this.linkHome.Name = "linkHome";
this.linkHome.Size = new System.Drawing.Size(145, 16);
this.linkHome.TabIndex = 6;
this.linkHome.TabStop = true;
this.linkHome.Text = "www.devcomponents.com";
this.linkHome.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkHome_LinkClicked);
//
// groupBox1
//
this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label7,
this.linkOrder,
this.label6,
this.label5});
this.groupBox1.Location = new System.Drawing.Point(14, 55);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(294, 135);
this.groupBox1.TabIndex = 8;
this.groupBox1.TabStop = false;
//
// label7
//
this.label7.Location = new System.Drawing.Point(3, 104);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(285, 12);
this.label7.TabIndex = 3;
this.label7.Text = "Order at:";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// linkOrder
//
this.linkOrder.Location = new System.Drawing.Point(6, 116);
this.linkOrder.Name = "linkOrder";
this.linkOrder.Size = new System.Drawing.Size(280, 15);
this.linkOrder.TabIndex = 2;
this.linkOrder.TabStop = true;
this.linkOrder.Text = "http://www.devcomponents.com/dotnetbar/order.html";
this.linkOrder.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.linkOrder.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkOrder_LinkClicked);
//
// label6
//
this.label6.Location = new System.Drawing.Point(9, 72);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(276, 31);
this.label6.TabIndex = 1;
this.label6.Text = "For pricing and licensing information please visit our web site. ";
//
// label5
//
this.label5.ForeColor = System.Drawing.Color.Maroon;
this.label5.Location = new System.Drawing.Point(8, 20);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(276, 41);
this.label5.TabIndex = 0;
this.label5.Text = "This component is not registered and it is provided for evaluation purposes only." +
" This message will not appear after you register the component.";
//
// RemindForm
//
this.BackColor=Color.WhiteSmoke;
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(321, 273);
this.ControlBox = false;
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.groupBox1,
this.label4,
this.label3,
this.label2,
this.label1,
this.linkHome,
this.linkEmail,
this.button2,
this.button1});
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "RemindForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Component not registered";
this.groupBox1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void timer1_Tick(object sender, System.EventArgs e)
{
timer1.Enabled=false;
button1.Enabled=true;
button1.Focus();
}
private void button2_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start(linkOrder.Text);
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void linkHome_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("http://www.devcomponents.com");
}
private void linkEmail_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start("mailto:info@devcomponents.com");
}
private void linkOrder_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(linkOrder.Text);
}
}
}

View File

@@ -0,0 +1,105 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>1.3</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="timer1.Location" type="System.Drawing.Point, System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</data>
<data name="$this.Name">
<value>RemindForm</value>
</data>
</root>