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,224 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{3084E369-3D7B-4918-958F-2776DA03E6BC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DevComponents.Instrumentation</RootNamespace>
<AssemblyName>DevComponents.Instrumentation</AssemblyName>
<StartupObject>
</StartupObject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>DotNetBarKnobControl.snk</AssemblyOriginatorKeyFile>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation />
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;/define:TRIAL</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseTrial|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release2005|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<DocumentationFile>bin\Release\DevComponents.Instrumentation.XML</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseTrial2005|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE;TRIAL</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<DocumentationFile>bin\Release\DevComponents.Instrumentation.XML</DocumentationFile>
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Gauges\GaugeControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Gauges\GaugeControl.Designer.cs">
<DependentUpon>GaugeControl.cs</DependentUpon>
</Compile>
<Compile Include="Gauges\GaugeFrame\GaugeFrameCircularRenderer.cs" />
<Compile Include="Gauges\GaugeFrame\GaugeFrameRectangularRenderer.cs" />
<Compile Include="Gauges\GaugeFrame\GaugeFrameRenderer.cs" />
<Compile Include="Gauges\GaugeFrame\GaugeFrameRoundRectRenderer.cs" />
<Compile Include="Gauges\GaugeIndicator\DigitalElement.cs" />
<Compile Include="Gauges\GaugeIndicator\GaugeIndicator.cs" />
<Compile Include="Gauges\GaugeIndicator\IndicatorRange.cs" />
<Compile Include="Gauges\GaugeIndicator\MechanicalElement.cs" />
<Compile Include="Gauges\GaugeIndicator\NumericElement.cs" />
<Compile Include="Gauges\GaugeIndicator\NumericIndicator.cs" />
<Compile Include="Gauges\GaugeIndicator\NumericRange.cs" />
<Compile Include="Gauges\GaugeIndicator\Seg16Element.cs" />
<Compile Include="Gauges\GaugeIndicator\Seg7Element.cs" />
<Compile Include="Gauges\GaugeIndicator\StateIndicator.cs" />
<Compile Include="Gauges\GaugeIndicator\StateRange.cs" />
<Compile Include="Gauges\GaugeLabel\GaugeCustomLabel.cs" />
<Compile Include="Gauges\GaugeLabel\GaugeBaseLabel.cs" />
<Compile Include="Gauges\GaugePin\GaugePinLabel.cs" />
<Compile Include="Gauges\GaugeScale\GaugeCircularScale.cs" />
<Compile Include="Gauges\GaugeScale\GaugeLinearScale.cs" />
<Compile Include="Gauges\GaugeTickMark\GaugeTickMarkLabel.cs" />
<Compile Include="Gauges\GaugeLabel\LabelLayout.cs" />
<Compile Include="Gauges\GaugeLabel\LabelPoint.cs" />
<Compile Include="Gauges\GaugeItem\GaugeMarker.cs" />
<Compile Include="Gauges\GaugePointers\GaugeBarRenderer.cs" />
<Compile Include="Gauges\GaugePointers\GaugeNeedleRenderer.cs" />
<Compile Include="Gauges\GaugePointers\GaugePointer.cs" />
<Compile Include="Gauges\GaugePointers\GaugeMarkerRenderer.cs" />
<Compile Include="Gauges\GaugeItem\GaugeItem.cs" />
<Compile Include="Gauges\GaugeLabel\GaugeIntervalLabel.cs" />
<Compile Include="Gauges\GaugePin\GaugePin.cs" />
<Compile Include="Gauges\GaugePointers\GaugePointerRenderer.cs" />
<Compile Include="Gauges\GaugePointers\GaugeThermoRenderer.cs" />
<Compile Include="Gauges\GaugeStrip\GaugeRange.cs" />
<Compile Include="Gauges\GaugeStrip\GaugeSection.cs" />
<Compile Include="Gauges\GaugeStrip\GaugeStrip.cs" />
<Compile Include="Gauges\GaugeItem\GaugeText.cs" />
<Compile Include="Gauges\GaugeTickMark\GaugeTickMark.cs" />
<Compile Include="Gauges\GaugeFrame\GaugeFrame.cs" />
<Compile Include="Gauges\GaugeItem\GaugeImage.cs">
</Compile>
<Compile Include="Gauges\GaugeScale\GaugeScale.cs" />
<Compile Include="Gauges\GaugeTickMark\GaugeTickMarkBase.cs" />
<Compile Include="Gauges\GaugeTickMark\TickMarkLayout.cs" />
<Compile Include="Gauges\GaugeTickMark\TickPoint.cs" />
<Compile Include="Gauges\GaugeItem\GradientFillColor.cs" />
<Compile Include="Gauges\Licensing.cs" />
<Compile Include="Gauges\PointFConverter.cs" />
<Compile Include="Gauges\RemindForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Knobs\BaseKnob.cs" />
<Compile Include="Primitives\GenericCollection.cs" />
<Compile Include="Primitives\ColorFactory.cs" />
<Compile Include="Knobs\KnobColorTable.cs" />
<Compile Include="Knobs\KnobControl.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Knobs\KnobControl.Designer.cs">
<DependentUpon>KnobControl.cs</DependentUpon>
</Compile>
<Compile Include="Knobs\KnobStyle1.cs" />
<Compile Include="Knobs\KnobStyle2.cs" />
<Compile Include="Knobs\KnobStyle3.cs" />
<Compile Include="Knobs\KnobStyle4.cs" />
<Compile Include="Primitives\LinearGradientColorTable.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="app.config" />
<None Include="DotNetBarKnobControl.snk" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Gauges\RemindForm.resx">
<DependentUpon>RemindForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="KnobControl.ico" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="GaugeControl.ico" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5 SP1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
<Visible>False</Visible>
<ProductName>Windows Installer 3.1</ProductName>
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 894 B

View File

@@ -0,0 +1,178 @@
namespace DevComponents.Instrumentation.Design
{
partial class FormatStringDropDown
{
/// <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()
{
this._CbxFmtType = new System.Windows.Forms.ComboBox();
this._LbFmtType = new System.Windows.Forms.Label();
this._LbPrecision = new System.Windows.Forms.Label();
this._LbSample = new System.Windows.Forms.Label();
this._TbSample = new System.Windows.Forms.TextBox();
this._LbDescription = new System.Windows.Forms.Label();
this._TbCustom = new System.Windows.Forms.TextBox();
this._TbPrecision = new System.Windows.Forms.TextBox();
this._BtnOk = new System.Windows.Forms.Button();
this._BtnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// _CbxFmtType
//
this._CbxFmtType.FormattingEnabled = true;
this._CbxFmtType.Location = new System.Drawing.Point(95, 17);
this._CbxFmtType.Name = "_CbxFmtType";
this._CbxFmtType.Size = new System.Drawing.Size(223, 21);
this._CbxFmtType.TabIndex = 0;
this._CbxFmtType.SelectedIndexChanged += new System.EventHandler(this.CbxFmtType_SelectedIndexChanged);
this._CbxFmtType.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
//
// _LbFmtType
//
this._LbFmtType.AutoSize = true;
this._LbFmtType.Location = new System.Drawing.Point(20, 20);
this._LbFmtType.Name = "_LbFmtType";
this._LbFmtType.Size = new System.Drawing.Size(69, 13);
this._LbFmtType.TabIndex = 1;
this._LbFmtType.Text = "Format Type:";
//
// _LbPrecision
//
this._LbPrecision.AutoSize = true;
this._LbPrecision.Location = new System.Drawing.Point(20, 44);
this._LbPrecision.Name = "_LbPrecision";
this._LbPrecision.Size = new System.Drawing.Size(53, 13);
this._LbPrecision.TabIndex = 2;
this._LbPrecision.Text = "Precision:";
//
// _LbSample
//
this._LbSample.AutoSize = true;
this._LbSample.Location = new System.Drawing.Point(20, 70);
this._LbSample.Name = "_LbSample";
this._LbSample.Size = new System.Drawing.Size(45, 13);
this._LbSample.TabIndex = 4;
this._LbSample.Text = "Sample:";
//
// _TbSample
//
this._TbSample.BackColor = System.Drawing.SystemColors.Info;
this._TbSample.ForeColor = System.Drawing.Color.Black;
this._TbSample.Location = new System.Drawing.Point(95, 70);
this._TbSample.Name = "_TbSample";
this._TbSample.Size = new System.Drawing.Size(223, 20);
this._TbSample.TabIndex = 5;
this._TbSample.Text = "1234.56";
this._TbSample.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
this._TbSample.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.TextBoxKeyPress);
//
// _LbDescription
//
this._LbDescription.Location = new System.Drawing.Point(15, 97);
this._LbDescription.Name = "_LbDescription";
this._LbDescription.Size = new System.Drawing.Size(391, 125);
this._LbDescription.TabIndex = 6;
this._LbDescription.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// _TbCustom
//
this._TbCustom.Location = new System.Drawing.Point(95, 44);
this._TbCustom.Name = "_TbCustom";
this._TbCustom.Size = new System.Drawing.Size(223, 20);
this._TbCustom.TabIndex = 7;
this._TbCustom.Visible = false;
this._TbCustom.TextChanged += new System.EventHandler(this.MyTextChanged);
this._TbCustom.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
//
// _TbPrecision
//
this._TbPrecision.Location = new System.Drawing.Point(95, 44);
this._TbPrecision.Name = "_TbPrecision";
this._TbPrecision.Size = new System.Drawing.Size(223, 20);
this._TbPrecision.TabIndex = 8;
this._TbPrecision.Visible = false;
this._TbPrecision.TextChanged += new System.EventHandler(this.MyTextChanged);
this._TbPrecision.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
//
// _BtnOk
//
this._BtnOk.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this._BtnOk.Location = new System.Drawing.Point(336, 26);
this._BtnOk.Name = "_BtnOk";
this._BtnOk.Size = new System.Drawing.Size(61, 23);
this._BtnOk.TabIndex = 9;
this._BtnOk.Text = "Ok";
this._BtnOk.UseVisualStyleBackColor = true;
this._BtnOk.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
this._BtnOk.Click += new System.EventHandler(this.BtnOk_Click);
//
// _BtnCancel
//
this._BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this._BtnCancel.Location = new System.Drawing.Point(336, 55);
this._BtnCancel.Name = "_BtnCancel";
this._BtnCancel.Size = new System.Drawing.Size(61, 23);
this._BtnCancel.TabIndex = 10;
this._BtnCancel.Text = "Cancel";
this._BtnCancel.UseVisualStyleBackColor = true;
this._BtnCancel.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.MyPreviewKeyDown);
this._BtnCancel.Click += new System.EventHandler(this.BtnCancel_Click);
//
// FormatStringDropDown
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this._BtnCancel);
this.Controls.Add(this._BtnOk);
this.Controls.Add(this._TbPrecision);
this.Controls.Add(this._LbDescription);
this.Controls.Add(this._TbSample);
this.Controls.Add(this._LbSample);
this.Controls.Add(this._LbPrecision);
this.Controls.Add(this._LbFmtType);
this.Controls.Add(this._CbxFmtType);
this.Controls.Add(this._TbCustom);
this.Name = "FormatStringDropDown";
this.Size = new System.Drawing.Size(418, 222);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ComboBox _CbxFmtType;
private System.Windows.Forms.Label _LbFmtType;
private System.Windows.Forms.Label _LbPrecision;
private System.Windows.Forms.Label _LbSample;
private System.Windows.Forms.TextBox _TbSample;
private System.Windows.Forms.Label _LbDescription;
private System.Windows.Forms.TextBox _TbCustom;
private System.Windows.Forms.TextBox _TbPrecision;
private System.Windows.Forms.Button _BtnOk;
private System.Windows.Forms.Button _BtnCancel;
}
}

View File

@@ -0,0 +1,322 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using DevComponents.DotNetBarKnobControl.Design.Properties;
namespace DevComponents.Instrumentation.Design
{
[ToolboxItem(false)]
public partial class FormatStringDropDown : UserControl
{
#region Private variables
private string _FormatString;
private bool _EscapePressed;
private IWindowsFormsEditorService _EditorService;
private ITypeDescriptorContext _Context;
private string[] _Items = new string[] {
"Custom",
"Currency",
"Decimal",
"Fixed-point",
"General",
"Hexadecimal",
"Number",
"Percent",
"Scientific"};
private Format[] _Formats = new Format[] {
new Format("", (string)(Resources.ResourceManager.GetObject("CustomDesc"))),
new Format("C", (string)(Resources.ResourceManager.GetObject("CurrencyDesc"))),
new Format("D", (string)(Resources.ResourceManager.GetObject("DecimalDesc"))),
new Format("F", (string)(Resources.ResourceManager.GetObject("FixedPointDesc"))),
new Format("G", (string)(Resources.ResourceManager.GetObject("GeneralDesc"))),
new Format("X", (string)(Resources.ResourceManager.GetObject("HexadecimalDesc"))),
new Format("N", (string)(Resources.ResourceManager.GetObject("NumericDesc"))),
new Format("P", (string)(Resources.ResourceManager.GetObject("PercentDesc"))),
new Format("E", (string)(Resources.ResourceManager.GetObject("ExponentialDesc")))};
#endregion
public FormatStringDropDown()
{
InitFormatList();
}
public FormatStringDropDown(string formatString,
IWindowsFormsEditorService editorService, ITypeDescriptorContext context)
{
_FormatString = formatString;
_EditorService = editorService;
_Context = context;
InitFormatList();
BackColor = SystemColors.Control;
}
#region InitFormatList
private void InitFormatList()
{
InitializeComponent();
_CbxFmtType.DrawMode = DrawMode.OwnerDrawFixed;
_CbxFmtType.DrawItem += CbxFmtType_DrawItem;
_CbxFmtType.Items.AddRange(_Items);
_CbxFmtType.SelectedIndex = 3;
}
#endregion
#region Public properties
#region FormatString
public string FormatString
{
get { return (_FormatString); }
set
{
_FormatString = value;
_Context.OnComponentChanging();
_Context.PropertyDescriptor.SetValue(_Context.Instance, value);
_Context.OnComponentChanged();
Invalidate();
}
}
#endregion
#region EditorService
public IWindowsFormsEditorService EditorService
{
get { return (_EditorService); }
set { _EditorService = value; }
}
#endregion
#region EscapePressed
public bool EscapePressed
{
get { return (_EscapePressed); }
set { _EscapePressed = value; }
}
#endregion
#endregion
#region CbxFmtType_DrawItem
void CbxFmtType_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index == 0)
{
e.Graphics.DrawLine(Pens.Gainsboro, new Point(e.Bounds.Left, e.Bounds.Bottom - 1),
new Point(e.Bounds.Right, e.Bounds.Bottom - 1));
}
TextRenderer.DrawText(e.Graphics, _CbxFmtType.Items[e.Index].ToString(),
_CbxFmtType.Font, e.Bounds, _CbxFmtType.ForeColor, TextFormatFlags.Left);
e.DrawFocusRectangle();
}
#endregion
#region TextBoxKeyPress
private void TextBoxKeyPress(object sender, KeyPressEventArgs e)
{
e.Handled = true;
}
#endregion
#region CbxFmtType_SelectedIndexChanged
private void CbxFmtType_SelectedIndexChanged(object sender, EventArgs e)
{
if ((uint)_CbxFmtType.SelectedIndex < _Formats.Length)
{
Format fmt = _Formats[_CbxFmtType.SelectedIndex];
_LbDescription.Text = fmt.Description;
UpdateSample();
}
else
{
_TbSample.Text = "";
_LbDescription.Text = "";
}
}
#endregion
#region UpdateSample
private void UpdateSample()
{
if (_CbxFmtType.SelectedIndex == 0)
{
_TbCustom.Visible = true;
_TbPrecision.Visible = false;
_LbPrecision.Text = @"Format String:";
UpdateCustomSample();
}
else if (_CbxFmtType.SelectedIndex > 0)
{
_TbPrecision.Visible = true;
_TbCustom.Visible = false;
_LbPrecision.Text = @"Precision:";
UpdateNumericSample();
}
}
#endregion
#region UpdateCustomSample
private void UpdateCustomSample()
{
_FormatString = _TbCustom.Text;
try
{
_TbSample.Text = String.Format("{0:" + _FormatString + "}", 1234567890);
}
catch
{
_TbSample.Text = @"Invalid Format String.";
}
}
#endregion
#region UpdateNumericSample
private void UpdateNumericSample()
{
Format fmt = _Formats[_CbxFmtType.SelectedIndex];
try
{
int precision = GetPrecision();
_FormatString = fmt.FormatCode + precision.ToString();
_TbSample.Text = String.Format("{0:" + _FormatString + "}", 1234567890);
}
catch
{
_TbSample.Text = @"Invalid Format String.";
}
}
#endregion
#region GetPrecision
private int GetPrecision()
{
int precision;
if (int.TryParse(_TbPrecision.Text, out precision))
return (precision < 0 ? 0 : precision > 99 ? 99 : precision);
return (0);
}
#endregion
#region MyTextChanged
private void MyTextChanged(object sender, EventArgs e)
{
UpdateSample();
}
#endregion
#region BtnOk_Click
private void BtnOk_Click(object sender, EventArgs e)
{
_EditorService.CloseDropDown();
}
#endregion
#region BtnCancel_Click
private void BtnCancel_Click(object sender, EventArgs e)
{
_EscapePressed = true;
_EditorService.CloseDropDown();
}
#endregion
#region MyPreviewKeyDown
private void MyPreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_EscapePressed = true;
}
#endregion
#region Format
private class Format
{
#region Private variables
private string _FormatCode;
private string _Description;
#endregion
public Format(string formatCode, string description)
{
_FormatCode = formatCode;
_Description = description;
}
#region Public properties
public string FormatCode
{
get { return (_FormatCode); }
}
public string Description
{
get { return (_Description); }
}
#endregion
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,59 @@
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
public class FormatStringEditor : UITypeEditor
{
#region GetEditStyle
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return (UITypeEditorEditStyle.DropDown);
}
#endregion
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (false);
}
#endregion
#region EditValue
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
FormatStringDropDown fs = new
FormatStringDropDown((string)value, editorService, context);
fs.EscapePressed = false;
editorService.DropDownControl(fs);
if (fs.EscapePressed == true)
context.PropertyDescriptor.SetValue(context.Instance, value);
else
return (fs.FormatString);
}
}
return (base.EditValue(context, provider, value));
}
#endregion
}
}

View File

@@ -0,0 +1,738 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
using DevComponents.DotNetBarKnobControl.Design.Properties;
namespace DevComponents.Instrumentation.Design
{
public class GaugeCollectionEditor : CollectionEditor
{
#region Private variables
private ListBox _ListBox;
private GaugeItem _GaugeItem;
private GaugeItem _LastGaugeItem;
private PropertyGrid _PropertyGrid;
private Button _AddButton;
private Button _RemButton;
private Button _CopyButton;
private ToolTip _ToolTip;
private List<GaugeItem> _RemovedItems;
#endregion
public GaugeCollectionEditor(Type type)
: base(type)
{
}
#region Private properties
#region RemovedItems
private List<GaugeItem> RemovedItems
{
get
{
if (_RemovedItems == null)
_RemovedItems = new List<GaugeItem>();
return (_RemovedItems);
}
}
#endregion
#endregion
#region CreateCollectionForm
protected override CollectionForm CreateCollectionForm()
{
CollectionForm collectionForm = base.CreateCollectionForm();
_GaugeItem = null;
if (collectionForm.Controls[0] is TableLayoutPanel)
{
TableLayoutPanel tlpf = collectionForm.Controls["overArchingTableLayoutPanel"] as TableLayoutPanel;
if (tlpf != null)
{
TableLayoutPanel tlp2 = tlpf.Controls["addRemoveTableLayoutPanel"] as TableLayoutPanel;
if (tlp2 != null)
{
_RemButton = tlp2.Controls["removeButton"] as Button;
if (_RemButton != null)
_RemButton.Click += GaugeCollectionEditor_RemoveClick;
_AddButton = tlp2.Controls["addButton"] as Button;
if (_AddButton != null)
{
_AddButton.Click += GaugeCollectionEditor_AddClick;
AddCopyButton(collectionForm);
}
}
_ListBox = tlpf.Controls["listbox"] as ListBox;
if (_ListBox != null)
_ListBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
_PropertyGrid = tlpf.Controls["propertyBrowser"] as PropertyGrid;
if (_PropertyGrid != null)
_PropertyGrid.HelpVisible = true;
}
}
return (collectionForm);
}
#endregion
#region CancelChanges
protected override void CancelChanges()
{
if (_RemovedItems != null)
{
foreach (GaugeItem gi in _RemovedItems)
gi.Visible = true;
}
base.CancelChanges();
}
#endregion
#region CopyButton support
#region AddCopyButton
private void AddCopyButton(CollectionForm collectionForm)
{
_CopyButton = new Button();
_CopyButton.Size = new Size(23, 24);
_CopyButton.Enabled = false;
_CopyButton.Click += CopyButton_Click;
ResourceManager rm = Resources.ResourceManager;
_CopyButton.Image = (Image)rm.GetObject("Copy");
collectionForm.Controls.Add(_CopyButton);
_CopyButton.Location = new Point(208, 85);
_CopyButton.BringToFront();
_ToolTip = new ToolTip();
_ToolTip.SetToolTip(_CopyButton, "Clone the selected item");
}
#endregion
#region CopyButton_Click
#region CopyButton_Click
void CopyButton_Click(object sender, EventArgs e)
{
if (_GaugeItem != null)
{
if (_GaugeItem is GaugeCircularScale)
CopyCircularScale(_GaugeItem as GaugeCircularScale);
else if (_GaugeItem is GaugeLinearScale)
CopyLinearScale(_GaugeItem as GaugeLinearScale);
else if (_GaugeItem is GaugeSection)
CopySection(_GaugeItem as GaugeSection);
else if (_GaugeItem is GaugeRange)
CopyRange(_GaugeItem as GaugeRange);
else if (_GaugeItem is GaugeCustomLabel)
CopyLabel(_GaugeItem as GaugeCustomLabel);
else if (_GaugeItem is GaugePointer)
CopyPointer(_GaugeItem as GaugePointer);
else if (_GaugeItem is NumericRange)
CopyNumericRange(_GaugeItem as NumericRange);
else if (_GaugeItem is StateRange)
CopyStateRange(_GaugeItem as StateRange);
}
}
#endregion
#region CopyCircularScale
private void CopyCircularScale(GaugeCircularScale scale)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugeCircularScaleCollection css = scale.GaugeControl.CircularScales;
GaugeCircularScale clone = css[css.Count - 1];
scale.CopyToItem(clone);
}
}
#endregion
#region CopyLinearScale
private void CopyLinearScale(GaugeLinearScale scale)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugeLinearScaleCollection lss = scale.GaugeControl.LinearScales;
GaugeLinearScale clone = lss[lss.Count - 1];
scale.CopyToItem(clone);
}
}
#endregion
#region CopySection
private void CopySection(GaugeSection section)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugeSectionCollection sc = section.Scale.Sections;
GaugeSection clone = sc[sc.Count - 1];
section.CopyToItem(clone);
}
}
#endregion
#region CopyRange
private void CopyRange(GaugeRange range)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugeRangeCollection rc = range.Scale.Ranges;
GaugeRange clone = rc[rc.Count - 1];
range.CopyToItem(clone);
}
}
#endregion
#region CopyLabel
private void CopyLabel(GaugeCustomLabel label)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugeCustomLabelCollection lc = label.Scale.CustomLabels;
GaugeCustomLabel clone = lc[lc.Count - 1];
label.CopyToItem(clone);
}
}
#endregion
#region CopyPointer
private void CopyPointer(GaugePointer pointer)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
GaugePointerCollection pc = pointer.Scale.Pointers;
GaugePointer clone = pc[pc.Count - 1];
pointer.CopyToItem(clone);
}
}
#endregion
#region CopyNumericRange
private void CopyNumericRange(NumericRange range)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
NumericRangeCollection pc = range.NumericIndicator.Ranges;
NumericRange clone = pc[pc.Count - 1];
range.CopyToItem(clone);
}
}
#endregion
#region CopyStateRange
private void CopyStateRange(StateRange range)
{
if (_AddButton != null)
{
_AddButton.PerformClick();
StateRangeCollection pc = range.StateIndicator.Ranges;
StateRange clone = pc[pc.Count - 1];
range.CopyToItem(clone);
}
}
#endregion
#endregion
#endregion
#region ListBox_SelectedIndexChanged
void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (_ListBox.SelectedItem != null)
{
PropertyInfo p = _ListBox.SelectedItem.GetType().GetProperty("Value");
_LastGaugeItem = _GaugeItem;
_GaugeItem = (GaugeItem)p.GetValue(_ListBox.SelectedItem, null);
_CopyButton.Enabled = true;
}
else
{
_CopyButton.Enabled = false;
}
}
#endregion
#region GaugeCollectionEditor_AddClick
void GaugeCollectionEditor_AddClick(object sender, EventArgs e)
{
if (_GaugeItem != null)
{
if (_GaugeItem is GaugeCircularScale)
InitializeNewCircularScale(_GaugeItem as GaugeCircularScale);
else if (_GaugeItem is GaugeLinearScale)
InitializeNewLinearScale(_GaugeItem as GaugeLinearScale);
else if (_GaugeItem is GaugeSection)
InitializeNewSection(_GaugeItem as GaugeSection);
else if (_GaugeItem is GaugeRange)
InitializeNewRange(_GaugeItem as GaugeRange);
else if (_GaugeItem is GaugeCustomLabel)
InitializeNewCustomLabel(_GaugeItem as GaugeCustomLabel);
else if (_GaugeItem is GaugePointer)
InitializeNewPointer(_GaugeItem as GaugePointer);
else if (_GaugeItem is NumericRange)
InitializeNewNumericRange(_GaugeItem as NumericRange);
else if (_GaugeItem is StateRange)
InitializeNewStateRange(_GaugeItem as StateRange);
}
}
#region InitializeNewScale
#region InitializeNewCircularScale
private void InitializeNewCircularScale(GaugeCircularScale scale)
{
scale.Name = GetScaleName(scale);
GaugeSection section = new GaugeSection(scale);
section.Name = GetSectionName(scale);
section.FillColor = new GradientFillColor(Color.CornflowerBlue);
scale.Sections.Add(section);
}
#region GetScaleName
private string GetScaleName(GaugeCircularScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Scale" + i.ToString();
if (scale.GaugeControl.CircularScales[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region InitializeNewLinearScale
private void InitializeNewLinearScale(GaugeLinearScale scale)
{
scale.Orientation = GetDefaultOrientation(scale);
scale.Name = GetScaleName(scale);
GaugeSection section = new GaugeSection(scale);
section.Name = GetSectionName(scale);
section.FillColor = new GradientFillColor(Color.CornflowerBlue);
scale.Sections.Add(section);
}
#region GetDefaultOrientation
private Orientation GetDefaultOrientation(GaugeLinearScale scale)
{
foreach (GaugeLinearScale gls in scale.GaugeControl.LinearScales)
{
if (gls != scale)
return (gls.Orientation);
}
return (scale.GaugeControl.Width > scale.GaugeControl.Height
? Orientation.Horizontal : Orientation.Vertical);
}
#endregion
#region GetScaleName
private string GetScaleName(GaugeLinearScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Scale" + i.ToString();
if (scale.GaugeControl.LinearScales[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#endregion
#region InitializeNewSection
#region InitializeNewSection
private void InitializeNewSection(GaugeSection section)
{
section.StartValue = section.Scale.MinValue;
section.EndValue = section.Scale.MinValue + (section.Scale.MajorTickMarks.Interval * 2);
section.Name = GetSectionName(section.Scale);
section.FillColor = new GradientFillColor(Color.Lime);
}
#endregion
#region GetSectionName
private string GetSectionName(GaugeScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Section" + i.ToString();
if (scale.Sections[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region InitializeNewRange
#region InitializeNewRange
private void InitializeNewRange(GaugeRange range)
{
range.EndValue = range.Scale.MaxValue;
range.StartValue = range.EndValue - range.Scale.MajorTickMarks.Interval * 3;
range.Name = GetRangeName(range.Scale);
range.FillColor = new GradientFillColor(Color.Lime, Color.Red);
range.FillColor.BorderColor = Color.Black;
range.FillColor.BorderWidth = 1;
}
#endregion
#region GetRangeName
private string GetRangeName(GaugeScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Range" + i.ToString();
if (scale.Ranges[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region InitializeNewCustomLabel
#region InitializeNewCustomLabel
private void InitializeNewCustomLabel(GaugeCustomLabel label)
{
label.Value = label.Scale.MinValue;
label.Name = GetLabelName(label.Scale);
}
#endregion
#region GetLabelName
private string GetLabelName(GaugeScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Label" + i.ToString();
if (scale.CustomLabels[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region InitializeNewPointer
#region InitializeNewPointer
private void InitializeNewPointer(GaugePointer pointer)
{
pointer.Style = (pointer.Scale is GaugeCircularScale)
? PointerStyle.Needle : PointerStyle.Marker;
pointer.Name = GetPointerName(pointer.Scale);
pointer.FillColor = new GradientFillColor(Color.WhiteSmoke, Color.Red);
pointer.FillColor.BorderColor = Color.DimGray;
pointer.FillColor.BorderWidth = 1;
Color color1 = Color.FromArgb(100, 60, 60, 60);
pointer.ThermoBackColor = new GradientFillColor(color1);
pointer.ThermoBackColor.BorderColor = Color.Black;
pointer.ThermoBackColor.BorderWidth = 1;
}
#endregion
#region GetPointerName
private string GetPointerName(GaugeScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Pointer" + i.ToString();
if (scale.Pointers[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#endregion
#region InitializeNewNumericRange
#region InitializeNewNumericRange
private void InitializeNewNumericRange(NumericRange range)
{
range.StartValue = 500;
range.EndValue = 1000;
range.Name = GetNumericRangeName(range.NumericIndicator);
range.DigitColor = Color.Red;
range.DigitDimColor = Color.FromArgb(94, 0, 0);
range.DecimalColor = range.DigitColor;
range.DecimalDimColor = range.DigitDimColor;
}
#endregion
#region GetNumericRangeName
private string GetNumericRangeName(NumericIndicator indicator)
{
for (int i = 1; i < 100; i++)
{
string s = "Range" + i.ToString();
if (indicator.Ranges[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region InitializeNewStateRange
#region InitializeNewStateRange
private void InitializeNewStateRange(StateRange range)
{
range.StartValue = 500;
range.EndValue = 1000;
range.Name = GetStateRangeName(range.StateIndicator);
}
#endregion
#region GetStateRangeName
private string GetStateRangeName(StateIndicator indicator)
{
for (int i = 1; i < 100; i++)
{
string s = "Range" + i.ToString();
if (indicator.Ranges[s] == null)
return (s);
}
return (null);
}
#endregion
#endregion
#region GaugeCollectionEditor_RemoveClick
void GaugeCollectionEditor_RemoveClick(object sender, EventArgs e)
{
if (_LastGaugeItem != null)
{
RemovedItems.Add(_LastGaugeItem);
_LastGaugeItem.Visible = false;
_LastGaugeItem = null;
}
else if (_GaugeItem != null)
{
RemovedItems.Add(_GaugeItem);
_GaugeItem.Visible = false;
_GaugeItem = null;
}
}
#endregion
}
#region CollectionChangedEventArgs
/// <summary>
/// CollectionChangedEventArgs
/// </summary>
public class CollectionChangedEventArgs : EventArgs
{
#region Private variables
private List<object> _NewList;
#endregion
public CollectionChangedEventArgs(List<object> newList)
{
_NewList = newList;
}
#region Public properties
/// <summary>
/// Gets the selected NewList
/// </summary>
public List<object> NewList
{
get { return (_NewList); }
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,332 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms;
using DevComponents.DotNetBarKnobControl.Design;
namespace DevComponents.Instrumentation.Design
{
public class GaugeControlActionList : DesignerActionList
{
#region Private variables
private GaugeControl _GaugeControl;
#endregion
/// <summary>
/// GaugeControlActionList
/// </summary>
/// <param name="gaugeControl">Associated GaugeControl</param>
public GaugeControlActionList(GaugeControl gaugeControl)
: base(gaugeControl)
{
_GaugeControl = gaugeControl;
}
#region Public properties
/// <summary>
/// Gets or sets the FrameStyle
/// </summary>
public GaugeFrameStyle FrameStyle
{
get { return (_GaugeControl.Frame.Style); }
set { GetFramePropertyByName("Style").SetValue(_GaugeControl.Frame, value); }
}
/// <summary>
/// Gets or sets the Glass Effect
/// </summary>
public bool AddGlassEffect
{
get { return (_GaugeControl.Frame.AddGlassEffect); }
set { GetFramePropertyByName("AddGlassEffect").SetValue(_GaugeControl.Frame, value); }
}
/// <summary>
/// Gets or sets the frame inner bevel size
/// </summary>
[Editor(typeof(HalfRadiusRangeValueEditor), typeof(UITypeEditor))]
public float InnerBevel
{
get { return (_GaugeControl.Frame.InnerBevel); }
set { GetFramePropertyByName("InnerBevel").SetValue(_GaugeControl.Frame, value); }
}
/// <summary>
/// Gets or sets the frame outer bevel size
/// </summary>
[Editor(typeof(HalfRadiusRangeValueEditor), typeof(UITypeEditor))]
public float OuterBevel
{
get { return (_GaugeControl.Frame.OuterBevel); }
set { GetFramePropertyByName("OuterBevel").SetValue(_GaugeControl.Frame, value); }
}
/// <summary>
/// Gets or sets the RoundRectangleArc size
/// </summary>
[Editor(typeof(HalfRadiusRangeValueEditor), typeof(UITypeEditor))]
public float RoundRectangleArc
{
get { return (_GaugeControl.Frame.RoundRectangleArc); }
set { GetFramePropertyByName("RoundRectangleArc").SetValue(_GaugeControl.Frame, value); }
}
#endregion
#region GetPropertyByName
/// <summary>
/// Gets the property via the given name
/// </summary>
/// <param name="propName">Property name</param>
/// <returns>PropertyDescriptor</returns>
private PropertyDescriptor GetPropertyByName(string propName)
{
PropertyDescriptor prop =
TypeDescriptor.GetProperties(_GaugeControl)[propName];
if (prop == null)
throw new ArgumentException("Matching property not found.", propName);
return (prop);
}
#endregion
#region GetFramePropertyByName
/// <summary>
/// Gets the Frame property via the given name
/// </summary>
/// <param name="propName">Property name</param>
/// <returns>PropertyDescriptor</returns>
private PropertyDescriptor GetFramePropertyByName(string propName)
{
PropertyDescriptor prop =
TypeDescriptor.GetProperties(_GaugeControl.Frame)[propName];
if (prop == null)
throw new ArgumentException("Matching property not found.", propName);
return (prop);
}
#endregion
#region GetSortedActionItems
/// <summary>
/// Gets the SortedActionItems
/// </summary>
/// <returns>DesignerActionItemCollection</returns>
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionMethodItem(this, "AddCircularScale", "Add Circular Scale", "Scale"));
items.Add(new DesignerActionMethodItem(this, "AddHLinearScale", "Add Horizontal Linear Scale", "Scale"));
items.Add(new DesignerActionMethodItem(this, "AddVLinearScale", "Add Vertical Linear Scale", "Scale"));
items.Add(new DesignerActionHeaderItem("Gauge Frame"));
items.Add(new DesignerActionPropertyItem("FrameStyle", "Style",
"Gauge Frame", "Sets the frame Style."));
items.Add(new DesignerActionPropertyItem("InnerBevel", "Inner Bevel",
"Gauge Frame", "Sets the frame inner bevel size."));
items.Add(new DesignerActionPropertyItem("OuterBevel", "Outer Bevel",
"Gauge Frame", "Sets the frame outer bevel size."));
items.Add(new DesignerActionPropertyItem("RoundRectangleArc", "Round Rectangle Arc",
"Gauge Frame", "Sets the rectangle corner arc."));
items.Add(new DesignerActionTextItem(
"Frame sizes are measured as a\n" +
"percentage of the width/height of the Gauge", "Gauge Frame"));
return (items);
}
#endregion
#region AddCircularScale
/// <summary>
/// Adds a CircularScale
/// </summary>
public void AddCircularScale()
{
GaugeCircularScale scale = NewCircularScale();
_GaugeControl.CircularScales.Add(scale);
GaugePropertyGrid prop = new GaugePropertyGrid();
prop.SelectedObject = scale;
DialogResult result = prop.ShowDialog();
if (result != DialogResult.OK)
_GaugeControl.CircularScales.Remove(scale);
}
#region NewCircularScale
private GaugeCircularScale NewCircularScale()
{
GaugeCircularScale scale = new GaugeCircularScale(_GaugeControl);
scale.Name = GetScaleName(scale);
GaugeSection section = new GaugeSection(scale);
section.Name = GetSectionName(scale);
section.FillColor = new GradientFillColor(Color.CornflowerBlue);
scale.Sections.Add(section);
return (scale);
}
#endregion
#endregion
#region AddHLinearScale
/// <summary>
/// Adds a Horizontal LinearScale
/// </summary>
public void AddHLinearScale()
{
GaugeLinearScale scale = NewLinearScale(Orientation.Horizontal);
_GaugeControl.LinearScales.Add(scale);
GaugePropertyGrid prop = new GaugePropertyGrid();
prop.SelectedObject = scale;
DialogResult result = prop.ShowDialog();
if (result != DialogResult.OK)
_GaugeControl.LinearScales.Remove(scale);
}
#endregion
#region AddVLinearScale
/// <summary>
/// Adds a Vertical LinearScale
/// </summary>
public void AddVLinearScale()
{
GaugeLinearScale scale = NewLinearScale(Orientation.Vertical);
_GaugeControl.LinearScales.Add(scale);
GaugePropertyGrid prop = new GaugePropertyGrid();
prop.SelectedObject = scale;
DialogResult result = prop.ShowDialog();
if (result != DialogResult.OK)
_GaugeControl.LinearScales.Remove(scale);
}
#endregion
#region NewLinearScale
private GaugeLinearScale NewLinearScale(Orientation orientation)
{
GaugeLinearScale scale = new GaugeLinearScale(_GaugeControl);
scale.Orientation = orientation;
scale.Name = GetScaleName(scale);
scale.MinPin.EndOffset = .028f;
scale.MaxPin.EndOffset = .028f;
GaugeSection section = new GaugeSection(scale);
section.Name = GetSectionName(scale);
section.FillColor = new GradientFillColor(Color.CornflowerBlue);
scale.Sections.Add(section);
return (scale);
}
#endregion
#region GetScaleName
private string GetScaleName(GaugeCircularScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Scale" + i.ToString();
if (scale.GaugeControl.CircularScales[s] == null)
return (s);
}
return (null);
}
private string GetScaleName(GaugeLinearScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Scale" + i.ToString();
if (scale.GaugeControl.LinearScales[s] == null)
return (s);
}
return (null);
}
#endregion
#region GetSectionName
private string GetSectionName(GaugeScale scale)
{
for (int i = 1; i < 100; i++)
{
string s = "Section" + i.ToString();
if (scale.Sections[s] == null)
return (s);
}
return (null);
}
#endregion
#region GetDefaultOrientation
private Orientation GetDefaultOrientation(GaugeLinearScale scale)
{
foreach (GaugeLinearScale gls in scale.GaugeControl.LinearScales)
{
if (gls != scale)
return (gls.Orientation);
}
return (scale.GaugeControl.Width > scale.GaugeControl.Height
? Orientation.Horizontal : Orientation.Vertical);
}
#endregion
}
}

View File

@@ -0,0 +1,337 @@
using System;
using System.ComponentModel.Design;
using System.Drawing;
using System.Reflection;
using System.Resources;
using System.Windows.Forms;
using DevComponents.DotNetBarKnobControl.Design.Properties;
namespace DevComponents.Instrumentation.Design
{
public class GaugeItemCollectionEditor : CollectionEditor
{
#region Private variables
private ListBox _ListBox;
private GaugeItem _CopyItem;
private GaugeItem _GaugeItem;
private GaugeItem _LastGaugeItem;
private PropertyGrid _PropertyGrid;
private ToolStripItem _AddTextItem;
private ToolStripItem _AddImageItem;
private ToolStripItem _AddDigitalIndicatorItem;
private ToolStripItem _AddMechanicalIndicatorItem;
private ToolStripItem _AddStateIndicatorItem;
private Button _CopyButton;
private ToolTip _ToolTip;
#endregion
public GaugeItemCollectionEditor(Type type)
: base(type)
{
_CopyItem = null;
}
#region CreateCollectionForm
protected override CollectionForm CreateCollectionForm()
{
CollectionForm collectionForm = base.CreateCollectionForm();
if (collectionForm.Controls[0] is TableLayoutPanel)
{
TableLayoutPanel tlpf = collectionForm.Controls["overArchingTableLayoutPanel"] as TableLayoutPanel;
if (tlpf != null)
{
TableLayoutPanel tlp2 = tlpf.Controls["addRemoveTableLayoutPanel"] as TableLayoutPanel;
if (tlp2 != null)
{
Button btn = tlp2.Controls["removeButton"] as Button;
if (btn != null)
btn.Click += GaugeCollectionEditor_RemoveClick;
btn = tlp2.Controls["addButton"] as Button;
if (btn != null)
{
_AddTextItem = btn.ContextMenuStrip.Items[0];
_AddImageItem = btn.ContextMenuStrip.Items[1];
_AddDigitalIndicatorItem = btn.ContextMenuStrip.Items[2];
_AddMechanicalIndicatorItem = btn.ContextMenuStrip.Items[3];
_AddStateIndicatorItem = btn.ContextMenuStrip.Items[4];
AddCopyButton(collectionForm);
}
}
_ListBox = tlpf.Controls["listbox"] as ListBox;
if (_ListBox != null)
_ListBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
_PropertyGrid = tlpf.Controls["propertyBrowser"] as PropertyGrid;
if (_PropertyGrid != null)
_PropertyGrid.HelpVisible = true;
}
}
return (collectionForm);
}
#endregion
#region CreateInstance
protected override object CreateInstance(Type itemType)
{
if (itemType == typeof(DigitalIndicator))
{
NumericIndicator ind = (NumericIndicator)
base.CreateInstance(typeof(NumericIndicator));
ind.Style = NumericIndicatorStyle.Digital16Segment;
ind.BackColor.BorderWidth = 3;
ind.BackColor.BorderColor = Color.Gray;
ind.BackColor.Color1 = Color.Black;
ind.DigitColor = Color.Red;
ind.DigitDimColor = Color.FromArgb(94, 0, 0);
ind.DecimalColor = Color.Lime;
ind.DecimalDimColor = Color.FromArgb(0, 94, 0);
ind.Size = new SizeF(.4f, .08f);
return (ind);
}
if (itemType == typeof(MechanicalIndicator))
{
NumericIndicator ind = (NumericIndicator)
base.CreateInstance(typeof(NumericIndicator));
ind.BackColor.BorderWidth = 1;
ind.BackColor.BorderColor = Color.Black;
ind.BackColor.Color1 = Color.Gray;
ind.BackColor.Color2 = Color.White;
ind.BackColor.GradientFillType = GradientFillType.HorizontalCenter;
ind.SeparatorColor.BorderWidth = 1;
ind.SeparatorColor.BorderColor = Color.Gray;
ind.SeparatorColor.Color1 = Color.LightGray;
ind.SeparatorColor.Color2 = Color.DimGray;
ind.SeparatorColor.GradientFillType = GradientFillType.HorizontalCenter;
ind.Size = new SizeF(.4f, .08f);
return (ind);
}
if (itemType == typeof(StateIndicator))
{
StateIndicator ind = (StateIndicator)
base.CreateInstance(typeof(StateIndicator));
ind.EmptyString = "";
return (ind);
}
return (base.CreateInstance(itemType));
}
#endregion
#region CopyButton support
#region AddCopyButton
private void AddCopyButton(CollectionForm collectionForm)
{
_CopyButton = new Button();
_CopyButton.Size = new Size(23, 24);
_CopyButton.Enabled = false;
_CopyButton.Click += CopyButton_Click;
ResourceManager rm = Resources.ResourceManager;
_CopyButton.Image = (Image)rm.GetObject("Copy");
collectionForm.Controls.Add(_CopyButton);
_CopyButton.Location = new Point(208, 85);
_CopyButton.BringToFront();
_ToolTip = new ToolTip();
_ToolTip.SetToolTip(_CopyButton, "Clone the selected item");
}
#endregion
#region CopyButton_Click
void CopyButton_Click(object sender, EventArgs e)
{
if (_GaugeItem != null)
{
_CopyItem = _GaugeItem;
if (_GaugeItem is GaugeText)
_AddTextItem.PerformClick();
else if (_GaugeItem is GaugeImage)
_AddImageItem.PerformClick();
else if (_GaugeItem is NumericIndicator)
{
if (((NumericIndicator) _GaugeItem).Style == NumericIndicatorStyle.Mechanical)
_AddMechanicalIndicatorItem.PerformClick();
else
_AddDigitalIndicatorItem.PerformClick();
}
else if (_GaugeItem is StateIndicator)
_AddStateIndicatorItem.PerformClick();
}
}
#endregion
#endregion
#region ListBox_SelectedIndexChanged
void ListBox_SelectedIndexChanged(object sender, EventArgs e)
{
if (_ListBox.SelectedItem != null)
{
PropertyInfo p = _ListBox.SelectedItem.GetType().GetProperty("Value");
_LastGaugeItem = _GaugeItem;
_GaugeItem = (GaugeItem)p.GetValue(_ListBox.SelectedItem, null);
if (_CopyItem != null)
{
if (_GaugeItem is GaugeText)
CopyGaugeText(_LastGaugeItem as GaugeText, _GaugeItem as GaugeText);
else if (_GaugeItem is GaugeImage)
CopyGaugeImage(_LastGaugeItem as GaugeImage, _GaugeItem as GaugeImage);
else if (_GaugeItem is NumericIndicator)
CopyGaugeNumericIndicator(_LastGaugeItem as NumericIndicator, _GaugeItem as NumericIndicator);
else if (_GaugeItem is StateIndicator)
CopyGaugeStateIndicator(_LastGaugeItem as StateIndicator, _GaugeItem as StateIndicator);
_CopyItem = null;
}
_CopyButton.Enabled = true;
}
else
{
_CopyButton.Enabled = false;
}
}
#endregion
#region CopyGaugeText
private void CopyGaugeText(GaugeText gt, GaugeText clone)
{
if (gt != null && clone != null)
gt.CopyToItem(clone);
}
#endregion
#region CopyGaugeImage
private void CopyGaugeImage(GaugeImage gi, GaugeImage clone)
{
if (gi != null && clone != null)
gi.CopyToItem(clone);
}
#endregion
#region CopyGaugeNumericIndicator
private void CopyGaugeNumericIndicator(NumericIndicator gi, NumericIndicator clone)
{
if (gi != null && clone != null)
gi.CopyToItem(clone);
}
#endregion
#region CopyGaugeStateIndicator
private void CopyGaugeStateIndicator(StateIndicator gi, StateIndicator clone)
{
if (gi != null && clone != null)
gi.CopyToItem(clone);
}
#endregion
#region CreateCollectionItemType
protected override Type CreateCollectionItemType()
{
return typeof(GaugeText);
}
#endregion
#region CreateNewItemTypes
protected override Type[] CreateNewItemTypes()
{
return new Type[]
{
typeof(GaugeText),
typeof(GaugeImage),
typeof(DigitalIndicator),
typeof(MechanicalIndicator),
typeof(StateIndicator),
};
}
private class DigitalIndicator : NumericIndicator
{
}
private class MechanicalIndicator : NumericIndicator
{
}
#endregion
#region GaugeCollectionEditor_RemoveClick
void GaugeCollectionEditor_RemoveClick(object sender, EventArgs e)
{
if (_LastGaugeItem != null)
{
_LastGaugeItem.Visible = false;
_LastGaugeItem = null;
}
else if (_GaugeItem != null)
{
_GaugeItem.Visible = false;
_GaugeItem = null;
}
}
#endregion
}
}

View File

@@ -0,0 +1,95 @@
namespace DevComponents.DotNetBarKnobControl.Design
{
partial class GaugePropertyGrid
{
/// <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 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.propertyGrid1 = new System.Windows.Forms.PropertyGrid();
this._BtnOk = new System.Windows.Forms.Button();
this._BtnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// propertyGrid1
//
this.propertyGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.propertyGrid1.Location = new System.Drawing.Point(0, 0);
this.propertyGrid1.Name = "propertyGrid1";
this.propertyGrid1.Size = new System.Drawing.Size(386, 408);
this.propertyGrid1.TabIndex = 0;
//
// _BtnOk
//
this._BtnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this._BtnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this._BtnOk.Location = new System.Drawing.Point(214, 427);
this._BtnOk.Name = "_BtnOk";
this._BtnOk.Size = new System.Drawing.Size(75, 23);
this._BtnOk.TabIndex = 1;
this._BtnOk.Text = "Ok";
this._BtnOk.UseVisualStyleBackColor = true;
//
// _BtnCancel
//
this._BtnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this._BtnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this._BtnCancel.Location = new System.Drawing.Point(295, 427);
this._BtnCancel.Name = "_BtnCancel";
this._BtnCancel.Size = new System.Drawing.Size(75, 23);
this._BtnCancel.TabIndex = 2;
this._BtnCancel.Text = "Cancel";
this._BtnCancel.UseVisualStyleBackColor = true;
//
// GaugePropertyGrid
//
this.AcceptButton = this._BtnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this._BtnCancel;
this.ClientSize = new System.Drawing.Size(384, 462);
this.Controls.Add(this._BtnCancel);
this.Controls.Add(this._BtnOk);
this.Controls.Add(this.propertyGrid1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.SizableToolWindow;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GaugePropertyGrid";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "GaugePropertyGrid";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PropertyGrid propertyGrid1;
private System.Windows.Forms.Button _BtnOk;
private System.Windows.Forms.Button _BtnCancel;
}
}

View File

@@ -0,0 +1,22 @@
using System.Windows.Forms;
namespace DevComponents.DotNetBarKnobControl.Design
{
public partial class GaugePropertyGrid : Form
{
public GaugePropertyGrid()
{
InitializeComponent();
}
#region Public properties
public object SelectedObject
{
get { return (propertyGrid1.SelectedObject); }
set { propertyGrid1.SelectedObject = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,335 @@
namespace DevComponents.DotNetBarKnobControl.Design
{
partial class GaugeStyleDialog
{
/// <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 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()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(GaugeStyleDialog));
this.label1 = new System.Windows.Forms.Label();
this.cbVThermometer = new System.Windows.Forms.CheckBox();
this.cbVMultiBars = new System.Windows.Forms.CheckBox();
this.cbV2Scales = new System.Windows.Forms.CheckBox();
this.cbVertical = new System.Windows.Forms.CheckBox();
this.cbHThermometer = new System.Windows.Forms.CheckBox();
this.cbHMultiBars = new System.Windows.Forms.CheckBox();
this.cbH2Scales = new System.Windows.Forms.CheckBox();
this.cbHorizontal = new System.Windows.Forms.CheckBox();
this.cbCTopMeter = new System.Windows.Forms.CheckBox();
this.cbCBottomMeter = new System.Windows.Forms.CheckBox();
this.cbCInsetScale = new System.Windows.Forms.CheckBox();
this.cbC2Scales = new System.Windows.Forms.CheckBox();
this.cbCircular = new System.Windows.Forms.CheckBox();
this.btnOk = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// label1
//
this.label1.BackColor = System.Drawing.SystemColors.ControlLight;
this.label1.Dock = System.Windows.Forms.DockStyle.Bottom;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.label1.Location = new System.Drawing.Point(0, 547);
this.label1.Name = "label1";
this.label1.Padding = new System.Windows.Forms.Padding(10, 0, 0, 0);
this.label1.Size = new System.Drawing.Size(736, 55);
this.label1.TabIndex = 4;
this.label1.Text = "Please select your starting Scale template";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// cbVThermometer
//
this.cbVThermometer.Appearance = System.Windows.Forms.Appearance.Button;
this.cbVThermometer.AutoCheck = false;
this.cbVThermometer.AutoSize = true;
this.cbVThermometer.Image = ((System.Drawing.Image)(resources.GetObject("cbVThermometer.Image")));
this.cbVThermometer.ImageAlign = System.Drawing.ContentAlignment.TopLeft;
this.cbVThermometer.Location = new System.Drawing.Point(545, 335);
this.cbVThermometer.Name = "cbVThermometer";
this.cbVThermometer.Size = new System.Drawing.Size(164, 181);
this.cbVThermometer.TabIndex = 40;
this.cbVThermometer.Text = "Thermometer";
this.cbVThermometer.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbVThermometer.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbVThermometer.UseVisualStyleBackColor = true;
this.cbVThermometer.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbVMultiBars
//
this.cbVMultiBars.Appearance = System.Windows.Forms.Appearance.Button;
this.cbVMultiBars.AutoCheck = false;
this.cbVMultiBars.AutoSize = true;
this.cbVMultiBars.Image = ((System.Drawing.Image)(resources.GetObject("cbVMultiBars.Image")));
this.cbVMultiBars.Location = new System.Drawing.Point(373, 335);
this.cbVMultiBars.Name = "cbVMultiBars";
this.cbVMultiBars.Size = new System.Drawing.Size(164, 181);
this.cbVMultiBars.TabIndex = 39;
this.cbVMultiBars.Text = "Multiple Bars";
this.cbVMultiBars.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbVMultiBars.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbVMultiBars.UseVisualStyleBackColor = true;
this.cbVMultiBars.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbV2Scales
//
this.cbV2Scales.Appearance = System.Windows.Forms.Appearance.Button;
this.cbV2Scales.AutoCheck = false;
this.cbV2Scales.AutoSize = true;
this.cbV2Scales.Image = ((System.Drawing.Image)(resources.GetObject("cbV2Scales.Image")));
this.cbV2Scales.Location = new System.Drawing.Point(201, 335);
this.cbV2Scales.Name = "cbV2Scales";
this.cbV2Scales.Size = new System.Drawing.Size(164, 181);
this.cbV2Scales.TabIndex = 38;
this.cbV2Scales.Text = "2 Scales";
this.cbV2Scales.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbV2Scales.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbV2Scales.UseVisualStyleBackColor = true;
this.cbV2Scales.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbVertical
//
this.cbVertical.Appearance = System.Windows.Forms.Appearance.Button;
this.cbVertical.AutoCheck = false;
this.cbVertical.AutoSize = true;
this.cbVertical.Image = ((System.Drawing.Image)(resources.GetObject("cbVertical.Image")));
this.cbVertical.Location = new System.Drawing.Point(29, 335);
this.cbVertical.Name = "cbVertical";
this.cbVertical.Size = new System.Drawing.Size(164, 181);
this.cbVertical.TabIndex = 37;
this.cbVertical.Text = "Vertical";
this.cbVertical.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbVertical.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbVertical.UseVisualStyleBackColor = true;
this.cbVertical.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbHThermometer
//
this.cbHThermometer.Appearance = System.Windows.Forms.Appearance.Button;
this.cbHThermometer.AutoCheck = false;
this.cbHThermometer.AutoSize = true;
this.cbHThermometer.Image = ((System.Drawing.Image)(resources.GetObject("cbHThermometer.Image")));
this.cbHThermometer.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft;
this.cbHThermometer.Location = new System.Drawing.Point(545, 216);
this.cbHThermometer.Name = "cbHThermometer";
this.cbHThermometer.Size = new System.Drawing.Size(166, 113);
this.cbHThermometer.TabIndex = 36;
this.cbHThermometer.Text = "Thermometer";
this.cbHThermometer.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbHThermometer.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbHThermometer.UseVisualStyleBackColor = true;
this.cbHThermometer.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbHMultiBars
//
this.cbHMultiBars.Appearance = System.Windows.Forms.Appearance.Button;
this.cbHMultiBars.AutoCheck = false;
this.cbHMultiBars.AutoSize = true;
this.cbHMultiBars.Image = ((System.Drawing.Image)(resources.GetObject("cbHMultiBars.Image")));
this.cbHMultiBars.Location = new System.Drawing.Point(373, 216);
this.cbHMultiBars.Name = "cbHMultiBars";
this.cbHMultiBars.Size = new System.Drawing.Size(166, 113);
this.cbHMultiBars.TabIndex = 35;
this.cbHMultiBars.Text = "Multiple Bars";
this.cbHMultiBars.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbHMultiBars.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbHMultiBars.UseVisualStyleBackColor = true;
this.cbHMultiBars.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbH2Scales
//
this.cbH2Scales.Appearance = System.Windows.Forms.Appearance.Button;
this.cbH2Scales.AutoCheck = false;
this.cbH2Scales.AutoSize = true;
this.cbH2Scales.Image = ((System.Drawing.Image)(resources.GetObject("cbH2Scales.Image")));
this.cbH2Scales.Location = new System.Drawing.Point(201, 216);
this.cbH2Scales.Name = "cbH2Scales";
this.cbH2Scales.Size = new System.Drawing.Size(166, 113);
this.cbH2Scales.TabIndex = 34;
this.cbH2Scales.Text = "2 Scales";
this.cbH2Scales.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbH2Scales.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbH2Scales.UseVisualStyleBackColor = true;
this.cbH2Scales.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbHorizontal
//
this.cbHorizontal.Appearance = System.Windows.Forms.Appearance.Button;
this.cbHorizontal.AutoCheck = false;
this.cbHorizontal.AutoSize = true;
this.cbHorizontal.Image = ((System.Drawing.Image)(resources.GetObject("cbHorizontal.Image")));
this.cbHorizontal.Location = new System.Drawing.Point(29, 216);
this.cbHorizontal.Name = "cbHorizontal";
this.cbHorizontal.Size = new System.Drawing.Size(166, 113);
this.cbHorizontal.TabIndex = 33;
this.cbHorizontal.Text = "Horizontal";
this.cbHorizontal.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbHorizontal.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbHorizontal.UseVisualStyleBackColor = true;
this.cbHorizontal.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbCTopMeter
//
this.cbCTopMeter.Appearance = System.Windows.Forms.Appearance.Button;
this.cbCTopMeter.AutoCheck = false;
this.cbCTopMeter.AutoSize = true;
this.cbCTopMeter.Image = ((System.Drawing.Image)(resources.GetObject("cbCTopMeter.Image")));
this.cbCTopMeter.Location = new System.Drawing.Point(545, 27);
this.cbCTopMeter.Name = "cbCTopMeter";
this.cbCTopMeter.Size = new System.Drawing.Size(166, 88);
this.cbCTopMeter.TabIndex = 32;
this.cbCTopMeter.Text = "Top Meter";
this.cbCTopMeter.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbCTopMeter.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbCTopMeter.UseVisualStyleBackColor = true;
this.cbCTopMeter.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbCBottomMeter
//
this.cbCBottomMeter.Appearance = System.Windows.Forms.Appearance.Button;
this.cbCBottomMeter.AutoCheck = false;
this.cbCBottomMeter.AutoSize = true;
this.cbCBottomMeter.Image = ((System.Drawing.Image)(resources.GetObject("cbCBottomMeter.Image")));
this.cbCBottomMeter.Location = new System.Drawing.Point(545, 122);
this.cbCBottomMeter.Name = "cbCBottomMeter";
this.cbCBottomMeter.Size = new System.Drawing.Size(166, 88);
this.cbCBottomMeter.TabIndex = 31;
this.cbCBottomMeter.Text = "Bottom Meter";
this.cbCBottomMeter.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbCBottomMeter.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbCBottomMeter.UseVisualStyleBackColor = true;
this.cbCBottomMeter.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbCInsetScale
//
this.cbCInsetScale.Appearance = System.Windows.Forms.Appearance.Button;
this.cbCInsetScale.AutoCheck = false;
this.cbCInsetScale.AutoSize = true;
this.cbCInsetScale.Image = ((System.Drawing.Image)(resources.GetObject("cbCInsetScale.Image")));
this.cbCInsetScale.Location = new System.Drawing.Point(373, 27);
this.cbCInsetScale.Name = "cbCInsetScale";
this.cbCInsetScale.Size = new System.Drawing.Size(166, 183);
this.cbCInsetScale.TabIndex = 30;
this.cbCInsetScale.Text = "Inset Scale";
this.cbCInsetScale.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbCInsetScale.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbCInsetScale.UseVisualStyleBackColor = true;
this.cbCInsetScale.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbC2Scales
//
this.cbC2Scales.Appearance = System.Windows.Forms.Appearance.Button;
this.cbC2Scales.AutoCheck = false;
this.cbC2Scales.AutoSize = true;
this.cbC2Scales.Image = ((System.Drawing.Image)(resources.GetObject("cbC2Scales.Image")));
this.cbC2Scales.Location = new System.Drawing.Point(201, 27);
this.cbC2Scales.Name = "cbC2Scales";
this.cbC2Scales.Size = new System.Drawing.Size(166, 183);
this.cbC2Scales.TabIndex = 29;
this.cbC2Scales.Text = "2 Scales";
this.cbC2Scales.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbC2Scales.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbC2Scales.UseVisualStyleBackColor = true;
this.cbC2Scales.Click += new System.EventHandler(this.CbCheckedChanged);
//
// cbCircular
//
this.cbCircular.Appearance = System.Windows.Forms.Appearance.Button;
this.cbCircular.AutoCheck = false;
this.cbCircular.AutoSize = true;
this.cbCircular.Checked = true;
this.cbCircular.CheckState = System.Windows.Forms.CheckState.Checked;
this.cbCircular.Image = ((System.Drawing.Image)(resources.GetObject("cbCircular.Image")));
this.cbCircular.Location = new System.Drawing.Point(29, 27);
this.cbCircular.Name = "cbCircular";
this.cbCircular.Size = new System.Drawing.Size(166, 183);
this.cbCircular.TabIndex = 28;
this.cbCircular.Text = "Circular";
this.cbCircular.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
this.cbCircular.TextImageRelation = System.Windows.Forms.TextImageRelation.ImageAboveText;
this.cbCircular.UseVisualStyleBackColor = true;
this.cbCircular.Click += new System.EventHandler(this.CbCheckedChanged);
//
// btnOk
//
this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOk.Location = new System.Drawing.Point(634, 563);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(75, 23);
this.btnOk.TabIndex = 41;
this.btnOk.Text = "Select";
this.btnOk.UseVisualStyleBackColor = true;
//
// GaugeStyleDialog
//
this.AcceptButton = this.btnOk;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(736, 602);
this.ControlBox = false;
this.Controls.Add(this.btnOk);
this.Controls.Add(this.cbVThermometer);
this.Controls.Add(this.cbVMultiBars);
this.Controls.Add(this.cbV2Scales);
this.Controls.Add(this.cbVertical);
this.Controls.Add(this.cbHThermometer);
this.Controls.Add(this.cbHMultiBars);
this.Controls.Add(this.cbH2Scales);
this.Controls.Add(this.cbHorizontal);
this.Controls.Add(this.cbCTopMeter);
this.Controls.Add(this.cbCBottomMeter);
this.Controls.Add(this.cbCInsetScale);
this.Controls.Add(this.cbC2Scales);
this.Controls.Add(this.cbCircular);
this.Controls.Add(this.label1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "GaugeStyleDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Initial Gauge Style";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.CheckBox cbVThermometer;
private System.Windows.Forms.CheckBox cbVMultiBars;
private System.Windows.Forms.CheckBox cbV2Scales;
private System.Windows.Forms.CheckBox cbVertical;
private System.Windows.Forms.CheckBox cbHThermometer;
private System.Windows.Forms.CheckBox cbHMultiBars;
private System.Windows.Forms.CheckBox cbH2Scales;
private System.Windows.Forms.CheckBox cbHorizontal;
private System.Windows.Forms.CheckBox cbCTopMeter;
private System.Windows.Forms.CheckBox cbCBottomMeter;
private System.Windows.Forms.CheckBox cbCInsetScale;
private System.Windows.Forms.CheckBox cbC2Scales;
private System.Windows.Forms.CheckBox cbCircular;
private System.Windows.Forms.Button btnOk;
}
}

View File

@@ -0,0 +1,60 @@
using System;
using System.Windows.Forms;
namespace DevComponents.DotNetBarKnobControl.Design
{
public partial class GaugeStyleDialog : Form
{
#region Private variables
private CheckBox _CheckedBox;
private DateTime _LastClick;
#endregion
public GaugeStyleDialog()
{
InitializeComponent();
_CheckedBox = cbCircular;
}
#region Public properties
public string CbSelected
{
get { return (_CheckedBox.Name); }
}
#endregion
#region CbCheckedChanged
private void CbCheckedChanged(object sender, EventArgs e)
{
CheckBox cb = sender as CheckBox;
if (cb != null)
{
if (_CheckedBox != cb)
{
_CheckedBox.Checked = false;
_CheckedBox = cb;
_CheckedBox.Checked = true;
}
else
{
TimeSpan ts = DateTime.Now - _LastClick;
if (ts.TotalMilliseconds < SystemInformation.DoubleClickTime)
btnOk.PerformClick();
}
}
_LastClick = DateTime.Now;
}
#endregion
}
}

View File

@@ -0,0 +1,183 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{37FBFDB8-C2D4-400F-A7EF-3CCA9258D805}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>DevComponents.DotNetBarKnobControl.Design</RootNamespace>
<AssemblyName>DevComponents.Instrumentation.Design</AssemblyName>
<StartupObject>
</StartupObject>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>KnobControlDesignTime.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseTrial|AnyCPU' ">
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release2005|AnyCPU' ">
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'ReleaseTrial2005|AnyCPU' ">
<OutputPath>..\bin\Release\</OutputPath>
<DefineConstants>TRACE;TRIAL</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="GaugeControlActionList.cs" />
<Compile Include="GaugeControlDesigner.cs" />
<Compile Include="FormatStringDropDown.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="FormatStringDropDown.Designer.cs">
<DependentUpon>FormatStringDropDown.cs</DependentUpon>
</Compile>
<Compile Include="FormatStringEditor.cs" />
<Compile Include="GaugeCollectionEditor.cs" />
<Compile Include="GaugeItemCollectionEditor.cs" />
<Compile Include="LocationDropDown.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="LocationDropDown.Designer.cs">
<DependentUpon>LocationDropDown.cs</DependentUpon>
</Compile>
<Compile Include="LocationEditor.cs" />
<Compile Include="PivotPointDropDown.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="PivotPointDropDown.Designer.cs">
<DependentUpon>PivotPointDropDown.cs</DependentUpon>
</Compile>
<Compile Include="PivotPointEditor.cs" />
<Compile Include="RangeValueDropDown.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="RangeValueDropDown.Designer.cs">
<DependentUpon>RangeValueDropDown.cs</DependentUpon>
</Compile>
<Compile Include="RangeValueEditor.cs" />
<Compile Include="SizeDropDown.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="SizeDropDown.Designer.cs">
<DependentUpon>SizeDropDown.cs</DependentUpon>
</Compile>
<Compile Include="SizeEditor.cs" />
<Compile Include="GaugePropertyGrid.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GaugePropertyGrid.Designer.cs">
<DependentUpon>GaugePropertyGrid.cs</DependentUpon>
</Compile>
<Compile Include="KnobControlActionList.cs" />
<Compile Include="KnobControlDesigner.cs" />
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="GaugeStyleDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GaugeStyleDialog.Designer.cs">
<DependentUpon>GaugeStyleDialog.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Design" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<None Include="KnobControlDesignTime.snk" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DevComponents.Instrumentation.csproj">
<Project>{3084E369-3D7B-4918-958F-2776DA03E6BC}</Project>
<Name>DevComponents.Instrumentation</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="FormatStringDropDown.resx">
<DependentUpon>FormatStringDropDown.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="LocationDropDown.resx">
<DependentUpon>LocationDropDown.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="PivotPointDropDown.resx">
<DependentUpon>PivotPointDropDown.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="RangeValueDropDown.resx">
<DependentUpon>RangeValueDropDown.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="SizeDropDown.resx">
<DependentUpon>SizeDropDown.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="GaugePropertyGrid.resx">
<SubType>Designer</SubType>
<DependentUpon>GaugePropertyGrid.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<SubType>Designer</SubType>
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="GaugeStyleDialog.resx">
<SubType>Designer</SubType>
<DependentUpon>GaugeStyleDialog.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Copy.png" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,175 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
namespace DevComponents.Instrumentation.Design
{
public class KnobControlActionList : DesignerActionList
{
#region Private variables
private KnobControl _KnobControl;
#endregion
/// <summary>
/// KnobControlActionList
/// </summary>
/// <param name="knobControl">Associated KnobControl</param>
public KnobControlActionList(KnobControl knobControl)
: base(knobControl)
{
_KnobControl = knobControl;
}
#region Public properties
/// <summary>
/// Gets or sets the KnobStyle
/// </summary>
public eKnobStyle KnobStyle
{
get { return (_KnobControl.KnobStyle); }
set { GetPropertyByName("KnobStyle").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the MinValue
/// </summary>
public decimal MinValue
{
get { return (_KnobControl.MinValue); }
set { GetPropertyByName("MinValue").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the MaxValue
/// </summary>
public decimal MaxValue
{
get { return (_KnobControl.MaxValue); }
set { GetPropertyByName("MaxValue").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the StartAngle
/// </summary>
public int StartAngle
{
get { return (_KnobControl.StartAngle); }
set { GetPropertyByName("StartAngle").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the SweepAngle
/// </summary>
public int SweepAngle
{
get { return (_KnobControl.SweepAngle); }
set { GetPropertyByName("SweepAngle").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the MaxValue
/// </summary>
public decimal MajorTickAmount
{
get { return (_KnobControl.MajorTickAmount); }
set { GetPropertyByName("MajorTickAmount").SetValue(_KnobControl, value); }
}
/// <summary>
/// Gets or sets the MinorTickAmount
/// </summary>
public decimal MinorTickAmount
{
get { return (_KnobControl.MinorTickAmount); }
set { GetPropertyByName("MinorTickAmount").SetValue(_KnobControl, value); }
}
#endregion
#region GetPropertyByName
/// <summary>
/// Gets the property via the given name
/// </summary>
/// <param name="propName">Property name</param>
/// <returns>PropertyDescriptor</returns>
private PropertyDescriptor GetPropertyByName(string propName)
{
PropertyDescriptor prop =
TypeDescriptor.GetProperties(_KnobControl)[propName];
if (prop == null)
throw new ArgumentException("Matching property not found.", propName);
return (prop);
}
#endregion
#region GetSortedActionItems
/// <summary>
/// Gets the SortedActionItems
/// </summary>
/// <returns>DesignerActionItemCollection</returns>
public override DesignerActionItemCollection GetSortedActionItems()
{
DesignerActionItemCollection items = new DesignerActionItemCollection();
items.Add(new DesignerActionPropertyItem("KnobStyle", "Knob Style",
"", "Sets the Knob Style."));
items.Add(new DesignerActionHeaderItem("Value Range"));
items.Add(new DesignerActionHeaderItem("Angle Range"));
items.Add(new DesignerActionPropertyItem("MinValue", "Minimum Value",
"Value Range", "Sets the minimum value permitted for the Knob value."));
items.Add(new DesignerActionPropertyItem("MaxValue", "Maximum Value",
"Value Range", "Sets the maximum value permitted for the Knob value."));
items.Add(new DesignerActionPropertyItem("MajorTickAmount", "MajorTick Amount",
"Value Range", "Sets the interval amount between major tick marks."));
items.Add(new DesignerActionPropertyItem("MinorTickAmount", "MinorTick Amount",
"Value Range", "Sets the interval amount between minor tick marks."));
items.Add(new DesignerActionPropertyItem("StartAngle", "Starting Angle",
"Angle Range", "Sets the Start angle."));
items.Add(new DesignerActionPropertyItem("SweepAngle", "Sweep Angle",
"Angle Range", "Sets the Sweep angle."));
items.Add(new DesignerActionMethodItem(this, "ReverseSweepAngle", "Reverse SweepAngle", "Angle Range"));
items.Add(new DesignerActionTextItem(
"SweepAngle can be positive or negative, denoting \n" +
"clockwise or counter-clockwise rotation, respectively", "Angle Range"));
return (items);
}
#endregion
#region ReverseSweepAngle
/// <summary>
/// Reverses the start and end angles for the control
/// </summary>
public void ReverseSweepAngle()
{
int angle = (StartAngle + SweepAngle) % 360;
if (angle < 0)
angle += 360;
StartAngle = angle;
SweepAngle = -SweepAngle;
}
#endregion
}
}

View File

@@ -0,0 +1,126 @@
using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
using DevComponents.Instrumentation;
namespace DevComponents.Instrumentation.Design
{
/// <summary>
/// KnobControlDesigner
/// </summary>
public class KnobControlDesigner : ControlDesigner
{
#region Private variables
private KnobControl _KnobControl;
private DesignerActionListCollection _ActionLists;
#endregion
#region Initialize
/// <summary>
/// Initializes our designer
/// </summary>
/// <param name="component"></param>
public override void Initialize(IComponent component)
{
base.Initialize(component);
if (component.Site.DesignMode == true)
_KnobControl = component as KnobControl;
}
#endregion
#region Verbs
/// <summary>
/// Creates our verb collection
/// </summary>
public override DesignerVerbCollection Verbs
{
get
{
DesignerVerb[] verbs = new DesignerVerb[]
{
new DesignerVerb("KnobStyle 1", SetStyle1),
new DesignerVerb("KnobStyle 2", SetStyle2),
new DesignerVerb("KnobStyle 3", SetStyle3),
new DesignerVerb("KnobStyle 4", SetStyle4),
};
return (new DesignerVerbCollection(verbs));
}
}
#endregion
#region SetStyle
/// <summary>
/// Sets the control to Style1
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void SetStyle1(object sender, EventArgs e)
{
_KnobControl.KnobStyle = eKnobStyle.Style1;
}
/// <summary>
/// Sets the control to Style2
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void SetStyle2(object sender, EventArgs e)
{
_KnobControl.KnobStyle = eKnobStyle.Style2;
}
/// <summary>
/// Sets the control to Style3
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void SetStyle3(object sender, EventArgs e)
{
_KnobControl.KnobStyle = eKnobStyle.Style3;
}
/// <summary>
/// Sets the control to Style4
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void SetStyle4(object sender, EventArgs e)
{
_KnobControl.KnobStyle = eKnobStyle.Style4;
}
#endregion
#region ActionLists
/// <summary>
/// Gets our DesignerActionListCollection list
/// </summary>
public override DesignerActionListCollection ActionLists
{
get
{
if (_ActionLists == null)
{
_ActionLists = new DesignerActionListCollection();
_ActionLists.Add(new KnobControlActionList(_KnobControl));
}
return (_ActionLists);
}
}
#endregion
}
}

View File

@@ -0,0 +1,48 @@
namespace DevComponents.Instrumentation.Design
{
partial class LocationDropDown
{
/// <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()
{
this.SuspendLayout();
//
// PivotPointDropDown
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "PivotPointDropDown";
this.Size = new System.Drawing.Size(99, 110);
this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.PivotPointDropDown_PreviewKeyDown);
this.ResumeLayout(false);
}
#endregion
}
}

View File

@@ -0,0 +1,248 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
[ToolboxItem(false)]
public partial class LocationDropDown : UserControl
{
#region Constants
private const int DotRadius = 4;
#endregion
#region Private variables
private PointF _PivotPoint;
private Rectangle _DotBounds;
private Rectangle _FrameBounds;
private Point _Center;
private bool _InFrame;
private bool _InPivotDot;
private bool _PivotMoving;
private bool _EscapePressed;
private IWindowsFormsEditorService _EditorService;
private ITypeDescriptorContext _Context;
#endregion
public LocationDropDown(PointF value,
IWindowsFormsEditorService editorService, ITypeDescriptorContext context)
{
Initialize();
_EditorService = editorService;
_Context = context;
PivotPoint = value;
}
public LocationDropDown()
{
Initialize();
}
#region Initialize
private void Initialize()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
#endregion
#region Public properties
#region EditorService
public IWindowsFormsEditorService EditorService
{
get { return (_EditorService); }
set { _EditorService = value; }
}
#endregion
#region EscapePressed
public bool EscapePressed
{
get { return (_EscapePressed); }
set { _EscapePressed = value; }
}
#endregion
#region PivotPoint
public PointF PivotPoint
{
get { return (_PivotPoint); }
set
{
_PivotPoint = value;
RecalcLayout();
Invalidate();
_Context.OnComponentChanging();
_Context.PropertyDescriptor.SetValue(_Context.Instance, value);
_Context.OnComponentChanged();
}
}
#endregion
#endregion
#region RecalcLayout
private void RecalcLayout()
{
int n = Math.Min(Bounds.Width - 4, Bounds.Height - 4);
_FrameBounds = new Rectangle(2, 2, n, n);
_FrameBounds.X = (Bounds.Width - n) / 2;
_FrameBounds.Y = (Bounds.Height - n) / 2;
int x = _FrameBounds.X + (int)(_PivotPoint.X * _FrameBounds.Width);
int y = _FrameBounds.Y + (int)(_PivotPoint.Y * _FrameBounds.Height);
_DotBounds = new Rectangle(x - DotRadius, y - DotRadius,
DotRadius * 2, DotRadius * 2);
_Center = new Point(_FrameBounds.X + _FrameBounds.Width / 2,
_FrameBounds.Y + _FrameBounds.Height / 2);
}
#endregion
#region Paint support
#region OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
RecalcLayout();
g.DrawLine(Pens.Red, new Point(_FrameBounds.X, _Center.Y),
new Point(_FrameBounds.Right, _Center.Y));
g.DrawLine(Pens.Red, new Point(_Center.X, _FrameBounds.Y),
new Point(_Center.X, _FrameBounds.Bottom));
DrawPivotDot(g);
}
#endregion
#region DrawPivotDot
private void DrawPivotDot(Graphics g)
{
g.FillEllipse(Brushes.SkyBlue, _DotBounds);
g.DrawEllipse(Pens.DimGray, _DotBounds);
}
#endregion
#endregion
#region Mouse support
#region OnMouseMove
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
_InFrame = (_FrameBounds.Contains(e.Location) == true);
if (_PivotMoving == true && _InFrame == true)
{
PivotPoint = new PointF(
(float)(e.X - _FrameBounds.X) / _FrameBounds.Width,
(float)(e.Y - _FrameBounds.Y) / _FrameBounds.Height);
}
_InPivotDot = (_DotBounds.Contains(e.Location) == true);
Cursor = (_InPivotDot == true) ? Cursors.Hand : Cursors.Default;
}
#endregion
#region OnMouseLeave
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
_InFrame = false;
_InPivotDot = false;
}
#endregion
#region OnMouseDown
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
if (_InPivotDot == true)
_PivotMoving = true;
}
}
#endregion
#region OnMouseUp
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
_PivotMoving = false;
_InFrame = (_FrameBounds.Contains(e.Location) == true);
_InPivotDot = (_DotBounds.Contains(e.Location) == true);
}
#endregion
#endregion
#region PivotPointDropDown_PreviewKeyDown
private void PivotPointDropDown_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_EscapePressed = true;
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,59 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
public class LocationEditor : UITypeEditor
{
#region GetEditStyle
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return (UITypeEditorEditStyle.DropDown);
}
#endregion
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (false);
}
#endregion
#region EditValue
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
LocationDropDown pv = new LocationDropDown((PointF)value, editorService, context);
pv.EscapePressed = false;
editorService.DropDownControl(pv);
if (pv.EscapePressed == true)
context.PropertyDescriptor.SetValue(context.Instance, value);
else
return (pv.PivotPoint);
}
}
return (base.EditValue(context, provider, value));
}
#endregion
}
}

View File

@@ -0,0 +1,48 @@
namespace DevComponents.Instrumentation.Design
{
partial class PivotPointDropDown
{
/// <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()
{
this.SuspendLayout();
//
// PivotPointDropDown
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "PivotPointDropDown";
this.Size = new System.Drawing.Size(99, 110);
this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.PivotPointDropDown_PreviewKeyDown);
this.ResumeLayout(false);
}
#endregion
}
}

View File

@@ -0,0 +1,425 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
[ToolboxItem(false)]
public partial class PivotPointDropDown : UserControl
{
#region Constants
private const int DotRadius = 4;
private const int ScaleWidth = 3;
private const float BevelInside = .035f;
private const float BevelOutside = .05f;
private const float RoundRectangleArc = .125f;
#endregion
#region Private variables
private GaugeFrameStyle _Style;
private PointF _PivotPoint;
private Rectangle _DotBounds;
private Rectangle _FrameBounds;
private Rectangle _ScaleBounds;
private float _ScaleRadius;
private float _StartAngle;
private float _SweepAngle;
private bool _InFrame;
private bool _InPivotDot;
private bool _PivotMoving;
private bool _EscapePressed;
private IWindowsFormsEditorService _EditorService;
private ITypeDescriptorContext _Context;
#endregion
public PivotPointDropDown(PointF value, GaugeFrameStyle style,
float scaleRadius, float startAngle, float sweepAngle,
IWindowsFormsEditorService editorService, ITypeDescriptorContext context)
{
_Style = style;
_ScaleRadius = scaleRadius;
_StartAngle = startAngle;
_SweepAngle = sweepAngle;
_ScaleRadius = Math.Max(_ScaleRadius, .07f);
Initialize();
_EditorService = editorService;
_Context = context;
PivotPoint = value;
}
public PivotPointDropDown()
{
Initialize();
}
#region Initialize
private void Initialize()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
#endregion
#region Public properties
#region EditorService
public IWindowsFormsEditorService EditorService
{
get { return (_EditorService); }
set { _EditorService = value; }
}
#endregion
#region EscapePressed
public bool EscapePressed
{
get { return (_EscapePressed); }
set { _EscapePressed = value; }
}
#endregion
#region PivotPoint
public PointF PivotPoint
{
get { return (_PivotPoint); }
set
{
_PivotPoint = value;
RecalcLayout();
Invalidate();
_Context.OnComponentChanging();
_Context.PropertyDescriptor.SetValue(_Context.Instance, value);
_Context.OnComponentChanged();
}
}
#endregion
#endregion
#region RecalcLayout
private void RecalcLayout()
{
int n = Math.Min(Bounds.Width - 4, Bounds.Height - 4);
_FrameBounds = new Rectangle(2, 2, n, n);
_FrameBounds.X = (Bounds.Width - n) / 2;
_FrameBounds.Y = (Bounds.Height - n) / 2;
int radius = (int)(n * _ScaleRadius);
_ScaleBounds.Width = radius * 2;
_ScaleBounds.Height = radius * 2;
int x = _FrameBounds.X + (int)(_PivotPoint.X * _FrameBounds.Width);
int y = _FrameBounds.Y + (int)(_PivotPoint.Y * _FrameBounds.Height);
_ScaleBounds.X = x - radius;
_ScaleBounds.Y = y - radius;
_DotBounds = new Rectangle(x - DotRadius, y - DotRadius, DotRadius * 2, DotRadius * 2);
}
#endregion
#region Paint support
#region OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
RecalcLayout();
DrawFrame(g);
DrawScale(g);
DrawPivotDot(g);
}
#endregion
#region DrawFrame
private void DrawFrame(Graphics g)
{
switch (_Style)
{
case GaugeFrameStyle.Circular:
DrawCircularFrame(g);
break;
case GaugeFrameStyle.Rectangular:
DrawRectangularFrame(g);
break;
case GaugeFrameStyle.RoundedRectangular:
DrawRoundedRectFrame(g);
break;
default:
DrawBlankFrame(g);
break;
}
}
#region DrawCircularFrame
private void DrawCircularFrame(Graphics g)
{
using (LinearGradientBrush br = new LinearGradientBrush(_FrameBounds, Color.WhiteSmoke, Color.Gray, 45))
g.FillEllipse(br, _FrameBounds);
int bevelIn = (int)(_FrameBounds.Width * BevelInside);
int bevelOut = (int)(_FrameBounds.Width * BevelOutside);
Rectangle r = _FrameBounds;
r.Inflate(-bevelOut, -bevelOut);
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.Gray, 45 + 180))
g.FillEllipse(br, r);
r.Inflate(-bevelIn, -bevelIn);
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.LightGray, 45))
g.FillEllipse(br, r);
}
#endregion
#region DrawRectangularFrame
private void DrawRectangularFrame(Graphics g)
{
using (LinearGradientBrush br = new LinearGradientBrush(_FrameBounds, Color.WhiteSmoke, Color.Gray, 45))
g.FillRectangle(br, _FrameBounds);
int bevelIn = (int)(_FrameBounds.Width * BevelInside);
int bevelOut = (int)(_FrameBounds.Width * BevelOutside);
Rectangle r = _FrameBounds;
r.Inflate(-bevelOut, -bevelOut);
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.Gray, 45 + 180))
g.FillRectangle(br, r);
r.Inflate(-bevelIn, -bevelIn);
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.LightGray, 45))
g.FillRectangle(br, r);
}
#endregion
#region DrawRoundedRectFrame
private void DrawRoundedRectFrame(Graphics g)
{
using (GraphicsPath path = GetRoundRectPath(_FrameBounds))
{
using (LinearGradientBrush br = new LinearGradientBrush(_FrameBounds, Color.WhiteSmoke, Color.Gray, 45))
g.FillPath(br, path);
}
int bevelIn = (int)(_FrameBounds.Width * BevelInside);
int bevelOut = (int)(_FrameBounds.Width * BevelOutside);
Rectangle r = _FrameBounds;
r.Inflate(-bevelOut, -bevelOut);
using (GraphicsPath path = GetRoundRectPath(r))
{
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.Gray, 45 + 180))
g.FillPath(br, path);
}
r.Inflate(-bevelIn, -bevelIn);
using (GraphicsPath path = GetRoundRectPath(r))
{
using (LinearGradientBrush br = new LinearGradientBrush(r, Color.Silver, Color.LightGray, 45))
g.FillPath(br, path);
}
}
#region GetRoundRectPath
private GraphicsPath GetRoundRectPath(Rectangle r)
{
GraphicsPath path = new GraphicsPath();
int m = Math.Min(r.Width, r.Height);
int n = (int)(m * RoundRectangleArc * 2) + 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
#endregion
#region DrawBlankFrame
private void DrawBlankFrame(Graphics g)
{
using (Brush br = new SolidBrush(Color.LightGray))
g.FillRectangle(br, _FrameBounds);
g.DrawRectangle(Pens.DimGray, _FrameBounds);
}
#endregion
#endregion
#region DrawScale
private void DrawScale(Graphics g)
{
using (Brush br = new SolidBrush(Color.CornflowerBlue))
{
using (Pen pen = new Pen(br, ScaleWidth))
g.DrawArc(pen, _ScaleBounds, _StartAngle, _SweepAngle);
}
}
#endregion
#region DrawPivotDot
private void DrawPivotDot(Graphics g)
{
g.FillEllipse(Brushes.SkyBlue, _DotBounds);
g.DrawEllipse(Pens.DimGray, _DotBounds);
}
#endregion
#endregion
#region Mouse support
#region OnMouseMove
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
_InFrame = (_FrameBounds.Contains(e.Location) == true);
if (_PivotMoving == true && _InFrame == true)
{
PivotPoint = new PointF(
(float)(e.X - _FrameBounds.X) / _FrameBounds.Width,
(float)(e.Y - _FrameBounds.Y) / _FrameBounds.Height);
}
_InPivotDot = (_DotBounds.Contains(e.Location) == true);
Cursor = (_InPivotDot == true) ? Cursors.Hand : Cursors.Default;
}
#endregion
#region OnMouseLeave
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
_InFrame = false;
_InPivotDot = false;
}
#endregion
#region OnMouseDown
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
if (_InPivotDot == true)
_PivotMoving = true;
}
}
#endregion
#region OnMouseUp
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
_PivotMoving = false;
_InFrame = (_FrameBounds.Contains(e.Location) == true);
_InPivotDot = (_DotBounds.Contains(e.Location) == true);
}
#endregion
#endregion
#region PivotPointDropDown_PreviewKeyDown
private void PivotPointDropDown_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_EscapePressed = true;
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,65 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
public class PivotPointEditor : UITypeEditor
{
#region GetEditStyle
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return (UITypeEditorEditStyle.DropDown);
}
#endregion
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (false);
}
#endregion
#region EditValue
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
GaugeCircularScale scale = context.Instance as GaugeCircularScale;
if (scale != null)
{
PivotPointDropDown pv = new PivotPointDropDown((PointF) value, scale.GaugeControl.Frame.Style,
scale.Radius, scale.StartAngle, scale.SweepAngle, editorService, context);
pv.EscapePressed = false;
editorService.DropDownControl(pv);
if (pv.EscapePressed == true)
context.PropertyDescriptor.SetValue(context.Instance, value);
else
return (pv.PivotPoint);
}
}
}
return (base.EditValue(context, provider, value));
}
#endregion
}
}

View File

@@ -0,0 +1,171 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:2.0.50727.4952
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DevComponents.DotNetBarKnobControl.Design.Properties {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DevComponents.DotNetBarKnobControl.Design.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
internal static System.Drawing.Bitmap Copy {
get {
object obj = ResourceManager.GetObject("Copy", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized string similar to The currency (&quot;C&quot;) format specifier converts a number to a string that represents a currency amount.
///
///The precision specifier indicates the desired number of decimal places in the result string..
/// </summary>
internal static string CurrencyDesc {
get {
return ResourceManager.GetString("CurrencyDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Characters that can be used to create custom numeric format strings:
///
///&apos;0&apos; - Zero placeholder, &apos;#&apos; - Digit placeholder, &apos;.&apos; - Decimal point, &apos;,&apos; - Group separator and number scaling , &apos;%&apos; - Percentage, &apos;E0&apos; - Scientific notation, &apos;\&apos; - Escape character, &apos;;&apos; - Section separator.
///
///All other characters are copied to the output string as literals in the position they appear..
/// </summary>
internal static string CustomDesc {
get {
return ResourceManager.GetString("CustomDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The decimal (&quot;D&quot;) format specifier converts a number to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. This format is supported only for integral types.
///
///The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. If no precision specifier is specified, the default is the minimum value required to represent th [rest of string was truncated]&quot;;.
/// </summary>
internal static string DecimalDesc {
get {
return ResourceManager.GetString("DecimalDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The exponential or Scientific (&quot;E&quot;) format specifier converts a number to a string of the form &quot;-d.ddd…E+ddd&quot; or &quot;-d.ddd…e+ddd&quot;, where each &quot;d&quot; indicates a digit (0-9). The string starts with a minus sign if the number is negative. Exactly one digit always precedes the decimal point.
///
///The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used..
/// </summary>
internal static string ExponentialDesc {
get {
return ResourceManager.GetString("ExponentialDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The fixed-point (&quot;F&quot;) format specifier converts a number to a string of the form &quot;-ddd.ddd…&quot; where each &quot;d&quot; indicates a digit (0-9). The string starts with a minus sign if the number is negative.
///
///The precision specifier indicates the desired number of decimal places..
/// </summary>
internal static string FixedPointDesc {
get {
return ResourceManager.GetString("FixedPointDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The general (&quot;G&quot;) format specifier converts a number to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present.
///
///The precision specifier defines the maximum number of significant digits that can appear in the result string..
/// </summary>
internal static string GeneralDesc {
get {
return ResourceManager.GetString("GeneralDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The hexadecimal (&quot;X&quot;) format specifier converts a number to a string of hexadecimal digits. This format is supported only for integral types.
///
///The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier..
/// </summary>
internal static string HexadecimalDesc {
get {
return ResourceManager.GetString("HexadecimalDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The numeric (&quot;N&quot;) format specifier converts a number to a string of the form &quot;-d,ddd,ddd.ddd…&quot;, where &quot;-&quot; indicates a negative number symbol if required, &quot;d&quot; indicates a digit (0-9), &quot;,&quot; indicates a group separator, and &quot;.&quot; indicates a decimal point symbol.
///
///The precision specifier indicates the desired number of decimal places..
/// </summary>
internal static string NumericDesc {
get {
return ResourceManager.GetString("NumericDesc", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The percent (&quot;P&quot;) format specifier multiplies a number by 100 and converts it to a string that represents a percentage.
///
///The precision specifier indicates the desired number of decimal places..
/// </summary>
internal static string PercentDesc {
get {
return ResourceManager.GetString("PercentDesc", resourceCulture);
}
}
}
}

View File

@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="Copy" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\Copy.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="CurrencyDesc" xml:space="preserve">
<value>The currency ("C") format specifier converts a number to a string that represents a currency amount.
The precision specifier indicates the desired number of decimal places in the result string.</value>
</data>
<data name="CustomDesc" xml:space="preserve">
<value>Characters that can be used to create custom numeric format strings:
'0' - Zero placeholder, '#' - Digit placeholder, '.' - Decimal point, ',' - Group separator and number scaling , '%' - Percentage, 'E0' - Scientific notation, '\' - Escape character, ';' - Section separator.
All other characters are copied to the output string as literals in the position they appear.</value>
</data>
<data name="DecimalDesc" xml:space="preserve">
<value>The decimal ("D") format specifier converts a number to a string of decimal digits (0-9), prefixed by a minus sign if the number is negative. This format is supported only for integral types.
The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. If no precision specifier is specified, the default is the minimum value required to represent the integer without leading zeros.</value>
</data>
<data name="ExponentialDesc" xml:space="preserve">
<value>The exponential or Scientific ("E") format specifier converts a number to a string of the form "-d.ddd…E+ddd" or "-d.ddd…e+ddd", where each "d" indicates a digit (0-9). The string starts with a minus sign if the number is negative. Exactly one digit always precedes the decimal point.
The precision specifier indicates the desired number of digits after the decimal point. If the precision specifier is omitted, a default of six digits after the decimal point is used.</value>
</data>
<data name="FixedPointDesc" xml:space="preserve">
<value>The fixed-point ("F") format specifier converts a number to a string of the form "-ddd.ddd…" where each "d" indicates a digit (0-9). The string starts with a minus sign if the number is negative.
The precision specifier indicates the desired number of decimal places.</value>
</data>
<data name="GeneralDesc" xml:space="preserve">
<value>The general ("G") format specifier converts a number to the most compact of either fixed-point or scientific notation, depending on the type of the number and whether a precision specifier is present.
The precision specifier defines the maximum number of significant digits that can appear in the result string.</value>
</data>
<data name="HexadecimalDesc" xml:space="preserve">
<value>The hexadecimal ("X") format specifier converts a number to a string of hexadecimal digits. This format is supported only for integral types.
The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier.</value>
</data>
<data name="NumericDesc" xml:space="preserve">
<value>The numeric ("N") format specifier converts a number to a string of the form "-d,ddd,ddd.ddd…", where "-" indicates a negative number symbol if required, "d" indicates a digit (0-9), "," indicates a group separator, and "." indicates a decimal point symbol.
The precision specifier indicates the desired number of decimal places.</value>
</data>
<data name="PercentDesc" xml:space="preserve">
<value>The percent ("P") format specifier multiplies a number by 100 and converts it to a string that represents a percentage.
The precision specifier indicates the desired number of decimal places.</value>
</data>
</root>

View File

@@ -0,0 +1,105 @@
namespace DevComponents.Instrumentation.Design
{
partial class RangeValueDropDown
{
/// <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()
{
this._TrackBar = new System.Windows.Forms.TrackBar();
this._LabelValue = new System.Windows.Forms.Label();
this._LabelMin = new System.Windows.Forms.Label();
this._LabelMax = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this._TrackBar)).BeginInit();
this.SuspendLayout();
//
// _TrackBar
//
this._TrackBar.AutoSize = false;
this._TrackBar.Dock = System.Windows.Forms.DockStyle.Fill;
this._TrackBar.Location = new System.Drawing.Point(0, 0);
this._TrackBar.Name = "_TrackBar";
this._TrackBar.Size = new System.Drawing.Size(186, 40);
this._TrackBar.TabIndex = 0;
this._TrackBar.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this._TrackBar_PreviewKeyDown);
this._TrackBar.ValueChanged += new System.EventHandler(this.TrackBar_ValueChanged);
//
// _LabelValue
//
this._LabelValue.AutoEllipsis = true;
this._LabelValue.Location = new System.Drawing.Point(59, 21);
this._LabelValue.Name = "_LabelValue";
this._LabelValue.Size = new System.Drawing.Size(69, 16);
this._LabelValue.TabIndex = 1;
this._LabelValue.Text = "Value";
this._LabelValue.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// _LabelMin
//
this._LabelMin.AutoEllipsis = true;
this._LabelMin.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
this._LabelMin.Location = new System.Drawing.Point(3, 21);
this._LabelMin.Name = "_LabelMin";
this._LabelMin.Size = new System.Drawing.Size(50, 16);
this._LabelMin.TabIndex = 2;
this._LabelMin.Text = "Min";
this._LabelMin.TextAlign = System.Drawing.ContentAlignment.BottomLeft;
//
// _LabelMax
//
this._LabelMax.AutoEllipsis = true;
this._LabelMax.ForeColor = System.Drawing.SystemColors.ControlDarkDark;
this._LabelMax.Location = new System.Drawing.Point(134, 21);
this._LabelMax.Name = "_LabelMax";
this._LabelMax.Size = new System.Drawing.Size(52, 16);
this._LabelMax.TabIndex = 3;
this._LabelMax.Text = "Max";
this._LabelMax.TextAlign = System.Drawing.ContentAlignment.BottomRight;
//
// RangeValueDropDown
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this._LabelMax);
this.Controls.Add(this._LabelMin);
this.Controls.Add(this._LabelValue);
this.Controls.Add(this._TrackBar);
this.Name = "RangeValueDropDown";
this.Size = new System.Drawing.Size(186, 40);
((System.ComponentModel.ISupportInitialize)(this._TrackBar)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.TrackBar _TrackBar;
private System.Windows.Forms.Label _LabelValue;
private System.Windows.Forms.Label _LabelMin;
private System.Windows.Forms.Label _LabelMax;
}
}

View File

@@ -0,0 +1,154 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
[ToolboxItem(false)]
public partial class RangeValueDropDown : UserControl
{
#region Private variables
private float _Value;
private bool _EscapePressed;
private IWindowsFormsEditorService _EditorService;
private ITypeDescriptorContext _Context;
#endregion
public RangeValueDropDown(float value, float minimum, float maximum,
IWindowsFormsEditorService editorService, ITypeDescriptorContext context)
{
InitializeComponent();
_EditorService = editorService;
_Context = context;
if (value < minimum)
{
if ((minimum * 1000 > Int16.MinValue) && (minimum * 1000 < Int16.MaxValue))
minimum = value;
}
if (value > maximum)
{
if ((maximum * 1000 > Int16.MinValue) && (maximum * 1000 < Int16.MaxValue))
maximum = value;
}
_TrackBar.Minimum = (int)(minimum * 1000);
_TrackBar.Maximum = (int)(maximum * 1000);
_TrackBar.SmallChange = _TrackBar.Maximum / 100;
_TrackBar.LargeChange = _TrackBar.Maximum / 10;
_TrackBar.TickFrequency = _TrackBar.LargeChange;
_TrackBar.Value = (int)(value * 1000);
_LabelMin.Text = String.Format("{0:f}", minimum);
_LabelMax.Text = String.Format("{0:f}", maximum);
Value = value;
}
public RangeValueDropDown()
{
InitializeComponent();
}
#region DefaultSize
protected override Size DefaultSize
{
get { return new Size(186, 40); }
}
#endregion
#region Public properties
#region EditorService
public IWindowsFormsEditorService EditorService
{
get { return (_EditorService); }
set { _EditorService = value; }
}
#endregion
#region EscapePressed
public bool EscapePressed
{
get { return (_EscapePressed); }
set { _EscapePressed = value; }
}
#endregion
#region Value
public float Value
{
get { return (_Value); }
set
{
_Value = value;
_LabelValue.Text = String.Format("{0:f3}", value);
_LabelValue.Update();
_Context.OnComponentChanging();
_Context.PropertyDescriptor.SetValue(_Context.Instance, value);
_Context.OnComponentChanged();
}
}
#endregion
#endregion
#region OnResize
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
int width = _TrackBar.Width;
int dx = width / 3;
_LabelMin.Width = dx;
_LabelMax.Width = dx;
_LabelValue.Width = dx;
_LabelValue.Location = new Point((width - dx) / 2, _LabelValue.Location.Y);
_LabelMax.Location = new Point(width - dx, _LabelMax.Location.Y);
}
#endregion
#region _TrackBar_ValueChanged
private void TrackBar_ValueChanged(object sender, EventArgs e)
{
Value = ((float)_TrackBar.Value) / 1000;
}
#endregion
#region _TrackBar_PreviewKeyDown
private void _TrackBar_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_EscapePressed = true;
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,218 @@
using System;
using System.ComponentModel;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
public class RangeValueEditor : UITypeEditor
{
#region Private variables
private const float MinValue = 0;
private const float MaxValue = 1;
#endregion
#region Public properties
public virtual float Minimum
{
get { return (MinValue); }
}
public virtual float Maximum
{
get { return (MaxValue); }
}
#endregion
#region GetEditStyle
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return (UITypeEditorEditStyle.DropDown);
}
#endregion
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (false);
}
#endregion
#region EditValue
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
RangeValueDropDown rv = new
RangeValueDropDown((float)value, Minimum, Maximum, editorService, context);
rv.EscapePressed = false;
editorService.DropDownControl(rv);
if (rv.EscapePressed == true)
context.PropertyDescriptor.SetValue(context.Instance, value);
else
return (rv.Value);
}
}
return (base.EditValue(context, provider, value));
}
#endregion
}
#region AngleRangeValueEditor
public class AngleRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (360); }
}
#endregion
}
#endregion
#region RadiusRangeValueEditor
public class RadiusRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (.5f); }
}
#endregion
}
#endregion
#region WidthRangeValueEditor
public class WidthRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (.3f); }
}
#endregion
}
#endregion
#region CapWidthRangeValueEditor
public class CapWidthRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (1f); }
}
#endregion
}
#endregion
#region OffsetRangeValueEditor
public class OffsetRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (.3f); }
}
public override float Minimum
{
get { return (-.3f); }
}
#endregion
}
#endregion
#region OffsetRangeValueEditor
public class OffsetPosRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (.9f); }
}
public override float Minimum
{
get { return (0f); }
}
#endregion
}
#endregion
#region WidthMaxRangeValueEditor
public class WidthMaxRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (1f); }
}
#endregion
}
#endregion
#region HalfRadiusRangeValueEditor
public class HalfRadiusRangeValueEditor : RangeValueEditor
{
#region Public properties
public override float Maximum
{
get { return (.5f); }
}
#endregion
}
#endregion
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

View File

@@ -0,0 +1,48 @@
namespace DevComponents.Instrumentation.Design
{
partial class SizeDropDown
{
/// <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()
{
this.SuspendLayout();
//
// PivotPointDropDown
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Name = "PivotPointDropDown";
this.Size = new System.Drawing.Size(99, 110);
this.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.PivotPointDropDown_PreviewKeyDown);
this.ResumeLayout(false);
}
#endregion
}
}

View File

@@ -0,0 +1,242 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
[ToolboxItem(false)]
public partial class SizeDropDown : UserControl
{
#region Constants
private const int DotRadius = 4;
#endregion
#region Private variables
private SizeF _Size;
private Rectangle _DotBounds;
private Rectangle _FrameBounds;
private Rectangle _DotRect;
private bool _InFrame;
private bool _InSizeDot;
private bool _PivotMoving;
private bool _EscapePressed;
private IWindowsFormsEditorService _EditorService;
private ITypeDescriptorContext _Context;
#endregion
public SizeDropDown(SizeF value,
IWindowsFormsEditorService editorService, ITypeDescriptorContext context)
{
Initialize();
_EditorService = editorService;
_Context = context;
_Size = value;
}
public SizeDropDown()
{
Initialize();
}
#region Initialize
private void Initialize()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
}
#endregion
#region Public properties
#region EditorService
public IWindowsFormsEditorService EditorService
{
get { return (_EditorService); }
set { _EditorService = value; }
}
#endregion
#region EscapePressed
public bool EscapePressed
{
get { return (_EscapePressed); }
set { _EscapePressed = value; }
}
#endregion
#region PivotPoint
public SizeF Syze
{
get { return (_Size); }
set
{
_Size = value;
RecalcLayout();
Invalidate();
_Context.OnComponentChanging();
_Context.PropertyDescriptor.SetValue(_Context.Instance, value);
_Context.OnComponentChanged();
}
}
#endregion
#endregion
#region RecalcLayout
private void RecalcLayout()
{
int n = Math.Min(Bounds.Width - 4, Bounds.Height - 4);
_FrameBounds = new Rectangle(2, 2, n, n);
_FrameBounds.X = (Bounds.Width - n) / 2;
_FrameBounds.Y = (Bounds.Height - n) / 2;
int x = _FrameBounds.X + (int)(_Size.Width * _FrameBounds.Width);
int y = _FrameBounds.Y + (int)(_Size.Height * _FrameBounds.Height);
_DotBounds = new Rectangle(x - DotRadius, y - DotRadius,
DotRadius * 2, DotRadius * 2);
_DotRect = new Rectangle(0, 0, x, y);
}
#endregion
#region Paint support
#region OnPaint
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
Graphics g = e.Graphics;
g.SmoothingMode = SmoothingMode.AntiAlias;
RecalcLayout();
g.DrawRectangle(Pens.Red, _DotRect);
DrawPivotDot(g);
}
#endregion
#region DrawPivotDot
private void DrawPivotDot(Graphics g)
{
g.FillEllipse(Brushes.SkyBlue, _DotBounds);
g.DrawEllipse(Pens.DimGray, _DotBounds);
}
#endregion
#endregion
#region Mouse support
#region OnMouseMove
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
_InFrame = (_FrameBounds.Contains(e.Location) == true);
if (_PivotMoving == true && _InFrame == true)
{
Syze = new SizeF(
(float)(e.X - _FrameBounds.X) / _FrameBounds.Width,
(float)(e.Y - _FrameBounds.Y) / _FrameBounds.Height);
}
_InSizeDot = (_DotBounds.Contains(e.Location) == true);
Cursor = (_InSizeDot == true) ? Cursors.Hand : Cursors.Default;
}
#endregion
#region OnMouseLeave
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
_InFrame = false;
_InSizeDot = false;
}
#endregion
#region OnMouseDown
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (e.Button == MouseButtons.Left)
{
if (_InSizeDot == true)
_PivotMoving = true;
}
}
#endregion
#region OnMouseUp
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
_PivotMoving = false;
_InFrame = (_FrameBounds.Contains(e.Location) == true);
_InSizeDot = (_DotBounds.Contains(e.Location) == true);
}
#endregion
#endregion
#region PivotPointDropDown_PreviewKeyDown
private void PivotPointDropDown_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if (e.KeyCode == Keys.Escape)
_EscapePressed = true;
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
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">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</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.Runtime.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:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<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" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</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>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,59 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.Design;
namespace DevComponents.Instrumentation.Design
{
public class SizeEditor : UITypeEditor
{
#region GetEditStyle
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return (UITypeEditorEditStyle.DropDown);
}
#endregion
#region GetPaintValueSupported
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (false);
}
#endregion
#region EditValue
public override object EditValue(
ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
IWindowsFormsEditorService editorService =
provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (editorService != null)
{
SizeDropDown pv = new SizeDropDown((SizeF)value, editorService, context);
pv.EscapePressed = false;
editorService.DropDownControl(pv);
if (pv.EscapePressed == true)
context.PropertyDescriptor.SetValue(context.Instance, value);
else
return (pv.Syze);
}
}
return (base.EditValue(context, provider, value));
}
#endregion
}
}

View File

@@ -0,0 +1,818 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
namespace DevComponents.Instrumentation.Primitives
{
public class BaseKnob
{
#region Private variables
private bool _Reset = true;
private int _KnobIndicatorPointerBorderWidth = -1;
#endregion
#region Protected variables
protected KnobControl Knob; // Associated KnobControl
protected int MajorTicks; // Number of major ticks
protected int MinorTicks; // Number of minor ticks
protected Size MajorTickSize; // Size of a major tick
protected Size MinorTickSize; // Size of a minor tick
protected int KnobWidth; // Normalized knob width
protected int IndTickHeight; // Ind tick height;
protected int MaxLabelWidth; // Maximum label width
protected float ZoneIndWidth; // Zone indicator width
protected KnobColorTable DefaultColorTable; // Default Knob color table
#endregion
#region Internal variables
internal Rectangle TickLabelBounds; // Tick Label bounding rectangle
internal Rectangle KnobFaceBounds; // Knob face bounding rectangle
internal Rectangle KnobIndicatorBounds; // Knob Indicator bounding rectangle
internal Rectangle FocusRectBounds; // Focus bounding rectangle
internal Rectangle ZoneIndicatorBounds; // Zone indicator bounding rectangle
#endregion
/// <summary>
/// Constructor
/// </summary>
/// <param name="knobControl">Associated knob control</param>
public BaseKnob(KnobControl knobControl)
{
Knob = knobControl;
DefaultColorTable = new KnobColorTable();
}
#region Public Properties
#region MajorTickColor
/// <summary>
/// MajorTickColor
/// </summary>
protected Color MajorTickColor
{
get
{
Color c = Knob.KnobColor.MajorTickColor;
return (c.IsEmpty == false ?
c : DefaultColorTable.MajorTickColor);
}
}
#endregion
#region MinorTickColor
/// <summary>
/// MinorTickColor
/// </summary>
protected Color MinorTickColor
{
get
{
Color c = Knob.KnobColor.MinorTickColor;
return (c.IsEmpty == false ?
c : DefaultColorTable.MinorTickColor);
}
}
#endregion
#region KnobIndicatorPointerBorderColor
/// <summary>
/// KnobIndicatorPointerBorderColor
/// </summary>
protected Color KnobIndicatorPointerBorderColor
{
get
{
Color c = Knob.KnobColor.KnobIndicatorPointerBorderColor;
return (c.IsEmpty == false ?
c : DefaultColorTable.KnobIndicatorPointerBorderColor);
}
}
#endregion
#region KnobIndicatorPointerBorderWidth
/// <summary>
/// KnobIndicatorPointerBorderWidth
/// </summary>
protected int KnobIndicatorPointerBorderWidth
{
get
{
int width = Knob.KnobColor.KnobIndicatorPointerBorderWidth;
if (width <= 0)
return (DefaultColorTable.KnobIndicatorPointerBorderWidth);
return (width);
}
}
#endregion
#region KnobIndicatorPointerColor
/// <summary>
/// KnobIndicatorPointerColor
/// </summary>
protected Color KnobIndicatorPointerColor
{
get
{
Color c = Knob.KnobColor.KnobIndicatorPointerColor;
return (c.IsEmpty == false ?
c : DefaultColorTable.KnobIndicatorPointerColor);
}
}
#endregion
#region ZoneIndicatorColor
/// <summary>
/// ZoneIndicatorBaseColor
/// </summary>
protected Color ZoneIndicatorColor
{
get
{
Color c = Knob.KnobColor.ZoneIndicatorColor;
return (c.IsEmpty == false ?
c : DefaultColorTable.ZoneIndicatorColor);
}
}
#endregion
#region KnobFaceColor
/// <summary>
/// KnobFaceColor
/// </summary>
protected LinearGradientColorTable KnobFaceColor
{
get
{
return (ApplyColor(Knob.KnobColor.KnobFaceColor,
DefaultColorTable.KnobFaceColor));
}
}
#endregion
#region KnobIndicatorColor
/// <summary>
/// KnobIndicatorColor
/// </summary>
protected LinearGradientColorTable KnobIndicatorColor
{
get
{
return (ApplyColor(Knob.KnobColor.KnobIndicatorColor,
DefaultColorTable.KnobIndicatorColor));
}
}
#endregion
#region LeftZoneIndicatorColor
/// <summary>
/// LeftZoneIndicatorColor
/// </summary>
protected LinearGradientColorTable LeftZoneIndicatorColor
{
get
{
return (ApplyColor(Knob.KnobColor.MinZoneIndicatorColor,
DefaultColorTable.MinZoneIndicatorColor));
}
}
#endregion
#region MiddleZoneIndicatorColor
/// <summary>
/// MiddleZoneIndicatorColor
/// </summary>
protected LinearGradientColorTable MiddleZoneIndicatorColor
{
get
{
return (ApplyColor(Knob.KnobColor.MidZoneIndicatorColor,
DefaultColorTable.MidZoneIndicatorColor));
}
}
#endregion
#region RightZoneIndicatorColor
/// <summary>
/// RightZoneIndicatorColor
/// </summary>
protected LinearGradientColorTable RightZoneIndicatorColor
{
get
{
return (ApplyColor(Knob.KnobColor.MaxZoneIndicatorColor,
DefaultColorTable.MaxZoneIndicatorColor));
}
}
#endregion
#region TickLabelFormat
/// <summary>
/// MajorTickColor
/// </summary>
protected string TickLabelFormat
{
get { return (Knob.TickLabelFormat); }
}
#endregion
#endregion
#region ApplyColor
/// <summary>
/// ApplyColor
/// </summary>
/// <param name="c"></param>
/// <param name="d"></param>
/// <returns></returns>
private LinearGradientColorTable ApplyColor(
LinearGradientColorTable c, LinearGradientColorTable d)
{
if (c.IsEmpty == true)
return (d);
if (c.Start.IsEmpty == false && c.End.IsEmpty == false)
return (c);
return (new LinearGradientColorTable(
c.Start.IsEmpty ? d.Start : c.Start,
c.End.IsEmpty ? d.End : c.End, c.GradientAngle));
}
#endregion
#region Knob configuration
#region ConfigureKnob
/// <summary>
/// Main control configuration routine
/// </summary>
/// <param name="e"></param>
public virtual void ConfigureKnob(PaintEventArgs e)
{
// Calculate the bounding width for the control to be the
// minimum of either the width and the height
KnobWidth = Math.Min(Knob.Width, Knob.Height);
KnobWidth = Math.Max(KnobWidth, Knob.MinKnobSize);
if ((KnobWidth % 2) != 0)
KnobWidth -= 1;
// Calculate the number of Major and Minor ticks and then
// measure each associated label so that we can mane sure we
// have enough room for them in the control rectangle
CalculateTicksCounts();
MeasureTickLabels();
}
#endregion
#region ResetKnob
/// <summary>
/// Sets the reset state to true, signifying
/// that the control needs to be reconfigured
/// before it is redrawn to the screen
/// </summary>
public void ResetKnob()
{
_Reset = true;
}
#endregion
#region InitRender
/// <summary>
/// Initializes the rendering process by making
/// sure that the control is reconfigured if
/// necessary
/// </summary>
/// <param name="e"></param>
public void InitRender(PaintEventArgs e)
{
if (_Reset == true)
{
ConfigureKnob(e);
_Reset = false;
}
}
#endregion
#endregion
#region Render processing
public virtual void RenderZoneIndicator(PaintEventArgs e) { }
public virtual void RenderKnobFace(PaintEventArgs e) { }
public virtual void RenderKnobIndicator(PaintEventArgs e) { }
#region RenderTickMinor
/// <summary>
/// Renders the minor tick marks
/// </summary>
/// <param name="e"></param>
public virtual void RenderTickMinor(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen pen = new Pen(MinorTickColor, MinorTickSize.Width))
{
for (int i = 0; i < MinorTicks; i++)
{
// Don't draw a minor tick if it overlaps
// with a previous major tick
if (Knob.MajorTickAmount > 0)
{
if ((i == 0 || i == MinorTicks - 1) ||
((Knob.MinorTickAmount * i) % Knob.MajorTickAmount == 0))
continue;
}
g.DrawLines(pen, GetMinorTickPoints(i));
}
}
}
/// <summary>
/// Calculates a series of points
/// that defines the tick mark
/// </summary>
/// <param name="tick">Tick to calculate</param>
/// <returns>An array of points that defines the tick</returns>
private Point[] GetMinorTickPoints(int tick)
{
float degree = GetTickDegree((float)Knob.MinorTickAmount, tick);
double rad = GetRadians(degree);
int dx = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int dy = ZoneIndicatorBounds.Y + ZoneIndicatorBounds.Height / 2;
int h = (int)(ZoneIndicatorBounds.Width / 2 + ZoneIndWidth / 2 - 1);
Point[] pts = new Point[2];
pts[0].X = (int)(Math.Cos(rad) * h + dx);
pts[0].Y = (int)(Math.Sin(rad) * h + dy);
pts[1].X = (int)(Math.Cos(rad) * (h + MinorTickSize.Height) + dx);
pts[1].Y = (int)(Math.Sin(rad) * (h + MinorTickSize.Height) + dy);
return (pts);
}
#endregion
#region RenderTickMajor
/// <summary>
/// Renders the Major Tick marks
/// </summary>
/// <param name="e"></param>
public virtual void RenderTickMajor(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Loop through each tick
using (Pen pen1 = new Pen(MajorTickColor, MajorTickSize.Width))
{
for (int i = 0; i < MajorTicks; i++)
g.DrawLines(pen1, GetMajorTickPoints(i));
}
}
/// <summary>
/// Calculates a series of points
/// that defines the tick mark
/// </summary>
/// <param name="tick">Tick to calculate</param>
/// <returns>An array of points that defines the tick</returns>
private Point[] GetMajorTickPoints(int tick)
{
float degree = GetTickDegree((float)Knob.MajorTickAmount, tick);
double rad = GetRadians(degree);
int dx = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int dy = ZoneIndicatorBounds.Y + ZoneIndicatorBounds.Height / 2;
int h = (int)(ZoneIndicatorBounds.Width / 2 + ZoneIndWidth / 2) - 1;
Point[] pts = new Point[2];
pts[0].X = (int)(Math.Cos(rad) * h + dx);
pts[0].Y = (int)(Math.Sin(rad) * h + dy);
pts[1].X = (int)(Math.Cos(rad) * (h + MajorTickSize.Height) + dx);
pts[1].Y = (int)(Math.Sin(rad) * (h + MajorTickSize.Height) + dy);
return (pts);
}
#endregion
#region RenderTickLabel
/// <summary>
/// Renders the major tick label
/// </summary>
/// <param name="e"></param>
public virtual void RenderTickLabel(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Allocate a StrFormat to use in the display
// of out tick label text
using (StringFormat strFormat = new StringFormat(StringFormatFlags.NoClip))
{
strFormat.Alignment = StringAlignment.Center;
float radius = TickLabelBounds.Width / 2;
// Grab our tick label font - which is
// dynamically sized according to the control
Font labelFont = Knob.Font;
int dx = KnobWidth / 2;
int dy = (KnobWidth - (int) labelFont.SizeInPoints) / 2;
// Loop through each major tick
float dpt = (float) (Knob.SweepAngle * Knob.MajorTickAmount / ValueCount);
for (int i = 0; i < MajorTicks; i++)
{
if (Math.Abs(dpt * i) < 360)
{
float degree = dpt * i + Knob.StartAngle;
if (dpt < 0)
{
if (degree < Knob.StartAngle + Knob.SweepAngle)
degree = Knob.StartAngle + Knob.SweepAngle;
}
else
{
if (degree > Knob.StartAngle + Knob.SweepAngle)
degree = Knob.StartAngle + Knob.SweepAngle;
}
decimal x = Math.Min(Knob.MinValue + (i * Knob.MajorTickAmount), Knob.MaxValue);
string s = ((int)x == x) ? ((int)x).ToString(TickLabelFormat) : x.ToString(TickLabelFormat);
Size sz = TextRenderer.MeasureText(s, labelFont);
double currentAngle = GetRadians(degree);
Point pt = new Point((int) (dx - sz.Width / 2 + radius * (float) Math.Cos(currentAngle)),
(int) (dy + radius * (float) Math.Sin(currentAngle)));
Rectangle r = new Rectangle(pt, new Size(1000, 1000));
TextRenderer.DrawText(g, s, labelFont, r,
Knob.ForeColor, TextFormatFlags.Left);
}
}
}
}
#endregion
#region RenderFocusRect
/// <summary>
/// Renders the base focus rect
/// </summary>
/// <param name="e"></param>
public virtual void RenderFocusRect(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen pen = new Pen(Color.DarkGray))
{
pen.DashStyle = DashStyle.Dash;
g.DrawEllipse(pen, FocusRectBounds);
}
}
#endregion
#endregion
#region GetValueFromPoint
/// <summary>
/// Determines the control Value from
/// a specified Point on the control
/// </summary>
/// <param name="pt">Point on the control</param>
/// <returns>Value</returns>
public decimal GetValueFromPoint(Point pt)
{
// Calculate the relative X and Y
// coordinate pair for the given point
int radius = ZoneIndicatorBounds.Width / 2;
Point cpt = new Point(ZoneIndicatorBounds.X + radius, ZoneIndicatorBounds.Y + radius);
int dx = pt.X - cpt.X;
int dy = pt.Y - cpt.Y;
// Determine the radians for the given coord pair
// based upon which quadrant it is located in
double radians;
if (dx >= 0)
{
if (dy >= 0)
radians = Math.Atan((double)dy / dx);
else
radians = -Math.Atan((double)dx / dy) + Math.PI * 1.5;
}
else
{
if (dy >= 0)
radians = -Math.Atan((double)dx / dy) + Math.PI / 2;
else
radians = Math.Atan((double)dy / dx) + Math.PI;
}
// Convert our calculated Radians to Degrees
// and then 'normalize' our values to the
// current StartAngle
int degrees = (int)GetDegrees(radians);
decimal normal = degrees - Knob.StartAngle;
if (Knob.SweepAngle < 0)
{
normal = 360 - normal;
normal = normal % 360;
}
if (normal < 0)
normal += 360;
// If our normalized angle is within the
// SweepAngle, then return the associated
// range value
int n = Math.Abs(Knob.SweepAngle);
if (normal >= 0 && normal <= n)
return (normal * ValueCount / n + Knob.MinValue);
// The normalized angle is outside the SweepAngle, so
// return either the MinValue or MaxValue (based upon
// which one is closer)
return ((normal >= n + (360 - n) / 2) ? Knob.MinValue : Knob.MaxValue);
}
#endregion
#region CalculateTicksCounts
/// <summary>
/// Calculate how many major and
/// minor ticks are presented on the control
/// </summary>
private void CalculateTicksCounts()
{
decimal count = ValueCount;
// Calculate the number of major ticks
MajorTicks = 0;
if (Knob.MajorTickAmount > 0)
{
MajorTicks = (int)(count / Knob.MajorTickAmount);
if (MajorTicks * Knob.MajorTickAmount < count)
MajorTicks++;
MajorTicks++;
}
// Calculate the number of minor ticks
MinorTicks = 0;
if (Knob.MinorTickAmount > 0)
{
MinorTicks = (int)(count / Knob.MinorTickAmount);
if (MinorTicks * Knob.MinorTickAmount < count)
MinorTicks++;
MinorTicks++;
}
}
#endregion
#region MeasureTickLabels
/// <summary>
/// Measure the width of each text label in order to
/// make sure we have room for it in the control
/// </summary>
private void MeasureTickLabels()
{
MaxLabelWidth = 0;
if (Knob.ShowTickLabels == true)
{
Font labelFont = Knob.Font;
for (int i = 0; i < MajorTicks; i++)
{
// Save the text and width for later use
decimal n = Knob.MinValue + (i * Knob.MajorTickAmount);
string s = n.ToString(TickLabelFormat);
int w = TextRenderer.MeasureText(s, labelFont).Width + 2;
// Keep track of the maximum width
if (w > MaxLabelWidth)
MaxLabelWidth = w;
}
}
}
#endregion
#region GetTickDegree
/// <summary>
/// Gets the arc degree associated with
/// the given gauge tick
/// </summary>
/// <param name="tickAmount">Major or minor tick amount</param>
/// <param name="tick">The tick to convert</param>
/// <returns></returns>
protected float GetTickDegree(float tickAmount, int tick)
{
float dpt = (Knob.SweepAngle * tickAmount) / (float)ValueCount;
float degree = dpt * tick + Knob.StartAngle;
if (dpt < 0)
{
if (degree < Knob.StartAngle + Knob.SweepAngle)
degree = Knob.StartAngle + Knob.SweepAngle;
}
else
{
if (degree > Knob.StartAngle + Knob.SweepAngle)
degree = Knob.StartAngle + Knob.SweepAngle;
}
return (degree);
}
#endregion
#region GetRadians
/// <summary>
/// Converts Degrees to Radians
/// </summary>
/// <param name="theta">Degrees</param>
/// <returns>Radians</returns>
public double GetRadians(float theta)
{
return (theta * Math.PI / 180);
}
#endregion
#region GetDegrees
/// <summary>
/// Converts Radians to Degrees
/// </summary>
/// <param name="radians">Radians</param>
/// <returns>Degrees</returns>
public double GetDegrees(double radians)
{
return (radians * 180 / Math.PI);
}
#endregion
#region ValueCount
/// <summary>
/// Gets the value range, expressed as a count
/// </summary>
internal decimal ValueCount
{
get { return (Knob.MaxValue - Knob.MinValue); }
}
#endregion
#region PointInControl
/// <summary>
/// Determines if a given Point is within
/// the bounds of the control
/// </summary>
/// <param name="pt"></param>
/// <returns></returns>
public virtual bool PointInControl(Point pt)
{
// Allow a little leeway around the control
Rectangle r = new Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size);
r.Inflate(40, 40);
int radius = r.Width / 2;
Point cpt = new Point(r.X + radius, r.Y + radius);
return (PointInCircle(pt, cpt, radius));
}
#endregion
#region PointInCircle
/// <summary>
/// Determines if a given point is within a given circle
/// </summary>
/// <param name="pt">Point in question</param>
/// <param name="cpt">Center Point</param>
/// <param name="radius">Circle radius</param>
/// <returns></returns>
public bool PointInCircle(Point pt, Point cpt, int radius)
{
int a = pt.X - cpt.X;
int b = pt.Y - cpt.Y;
int c = (int)Math.Sqrt(a * a + b * b);
return (c < radius);
}
#endregion
}
}

View File

@@ -0,0 +1,599 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Globalization;
using DevComponents.Instrumentation.Primitives;
namespace DevComponents.Instrumentation
{
[TypeConverter(typeof(KnobColorTableConvertor))]
public class KnobColorTable
{
public static readonly KnobColorTable Empty = new KnobColorTable();
#region Events
/// <summary>
/// Event raised when ColorTable has changed
/// </summary>
[Description("Event raised when ColorTable has changed.")]
public event EventHandler<EventArgs> ColorTableChanged;
#endregion
#region Private variables
private Color _MajorTickColor = Color.Empty;
private Color _MinorTickColor = Color.Empty;
private Color _ZoneIndicatorColor = Color.Empty;
private Color _KnobIndicatorPointerColor = Color.Empty;
private Color _KnobIndicatorPointerBorderColor = Color.Empty;
private LinearGradientColorTable _KnobFaceColor = new LinearGradientColorTable();
private LinearGradientColorTable _KnobIndicatorColor = new LinearGradientColorTable();
private LinearGradientColorTable _MinZoneIndicatorColor = new LinearGradientColorTable();
private LinearGradientColorTable _MaxZoneIndicatorColor = new LinearGradientColorTable();
private LinearGradientColorTable _MidZoneIndicatorColor = new LinearGradientColorTable();
private int _KnobIndicatorPointerBorderWidth;
#endregion
/// <summary>
/// Constructor
/// </summary>
public KnobColorTable()
{
_KnobFaceColor = new LinearGradientColorTable();
_KnobFaceColor.ColorTableChanged += KnobColorTableChanged;
_KnobIndicatorColor = new LinearGradientColorTable();
_KnobIndicatorColor.ColorTableChanged += KnobColorTableChanged;
_MinZoneIndicatorColor = new LinearGradientColorTable();
_MinZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
_MaxZoneIndicatorColor = new LinearGradientColorTable();
_MaxZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
_MidZoneIndicatorColor = new LinearGradientColorTable();
_MidZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
}
#region Public properties
#region MajorTickColor
/// <summary>
/// Gets or sets the color of the Major Tick marks
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the Major Tick marks")]
public Color MajorTickColor
{
get { return (_MajorTickColor); }
set
{
if (_MajorTickColor != value)
{
_MajorTickColor = value;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMajorTickColor()
{
return (_MajorTickColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMajorTickColor()
{
MajorTickColor = Color.Empty;
}
#endregion
#region MinorTickColor
/// <summary>
/// Gets or sets the color of the Minor Tick marks
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the Minor Tick marks")]
public Color MinorTickColor
{
get { return (_MinorTickColor); }
set
{
if (_MinorTickColor != value)
{
_MinorTickColor = value;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMinorTickColor()
{
return (_MinorTickColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMinorTickColor()
{
MinorTickColor = Color.Empty;
}
#endregion
#region KnobIndicatorPointerBorderColor
/// <summary>
/// Gets or sets the color of the KnobIndicatorPointer Border
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the KnobIndicatorPointer Border")]
public Color KnobIndicatorPointerBorderColor
{
get { return (_KnobIndicatorPointerBorderColor); }
set
{
if (_KnobIndicatorPointerBorderColor != value)
{
_KnobIndicatorPointerBorderColor = value;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeKnobIndicatorPointerBorderColor()
{
return (_KnobIndicatorPointerBorderColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetKnobIndicatorPointerBorderColor()
{
KnobIndicatorPointerBorderColor = Color.Empty;
}
#endregion
#region KnobIndicatorPointerBorderWidth
/// <summary>
/// Gets or sets the width of the KnobIndicatorPointer Border
/// </summary>
[Browsable(true), DefaultValue(0)]
[Description("Indicates the width of the KnobIndicatorPointer Border")]
public int KnobIndicatorPointerBorderWidth
{
get { return (_KnobIndicatorPointerBorderWidth); }
set
{
if (_KnobIndicatorPointerBorderWidth != value)
{
_KnobIndicatorPointerBorderWidth = value;
OnColorTableChange();
}
}
}
#endregion
#region KnobIndicatorPointerColor
/// <summary>
/// Gets or sets the color of the KnobIndicatorPointer
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the KnobIndicatorPointer")]
public Color KnobIndicatorPointerColor
{
get { return (_KnobIndicatorPointerColor); }
set
{
if (_KnobIndicatorPointerColor != value)
{
_KnobIndicatorPointerColor = value;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeKnobIndicatorPointerColor()
{
return (_KnobIndicatorPointerColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetKnobIndicatorPointerColor()
{
KnobIndicatorPointerColor = Color.Empty;
}
#endregion
#region ZoneIndicatorColor
/// <summary>
/// Gets or sets the color of the ZoneIndicator
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the ZoneIndicator")]
public Color ZoneIndicatorColor
{
get { return (_ZoneIndicatorColor); }
set
{
if (_ZoneIndicatorColor != value)
{
_ZoneIndicatorColor = value;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeZoneIndicatorColor()
{
return (_ZoneIndicatorColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetZoneIndicatorColor()
{
ZoneIndicatorColor = Color.Empty;
}
#endregion
#region KnobFaceColor
/// <summary>
/// Gets or sets the color of the KnobFace
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the KnobFace")]
public LinearGradientColorTable KnobFaceColor
{
get { return (_KnobFaceColor); }
set
{
if (_KnobFaceColor != value)
{
if (_KnobFaceColor != null)
_KnobFaceColor.ColorTableChanged -= KnobColorTableChanged;
_KnobFaceColor = value;
if (_KnobFaceColor != null)
_KnobFaceColor.ColorTableChanged += KnobColorTableChanged;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeKnobFaceColor()
{
return (_KnobFaceColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetKnobFaceColor()
{
KnobFaceColor = LinearGradientColorTable.Empty;
}
#endregion
#region KnobIndicatorColor
/// <summary>
/// Gets or sets the color of the KnobIndicator
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the KnobIndicator")]
public LinearGradientColorTable KnobIndicatorColor
{
get { return (_KnobIndicatorColor); }
set
{
if (_KnobIndicatorColor != value)
{
if (_KnobIndicatorColor != null)
_KnobIndicatorColor.ColorTableChanged -= KnobColorTableChanged;
_KnobIndicatorColor = value;
if (_KnobIndicatorColor != null)
_KnobIndicatorColor.ColorTableChanged += KnobColorTableChanged;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeKnobIndicatorColor()
{
return (_KnobIndicatorColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetKnobIndicatorColor()
{
KnobIndicatorColor = LinearGradientColorTable.Empty;
}
#endregion
#region MinZoneIndicatorColor
/// <summary>
/// Gets or sets the color of the MinZoneIndicator
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the MinZoneIndicator")]
public LinearGradientColorTable MinZoneIndicatorColor
{
get { return (_MinZoneIndicatorColor); }
set
{
if (_MinZoneIndicatorColor != value)
{
if (_MinZoneIndicatorColor != null)
_MinZoneIndicatorColor.ColorTableChanged -= KnobColorTableChanged;
_MinZoneIndicatorColor = value;
if (_MinZoneIndicatorColor != null)
_MinZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMinZoneIndicatorColor()
{
return (_MinZoneIndicatorColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMinZoneIndicatorColor()
{
MinZoneIndicatorColor = LinearGradientColorTable.Empty;
}
#endregion
#region MaxZoneIndicatorColor
/// <summary>
/// Gets or sets the color of the MaxZoneIndicator
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the MaxZoneIndicator")]
public LinearGradientColorTable MaxZoneIndicatorColor
{
get { return (_MaxZoneIndicatorColor); }
set
{
if (_MaxZoneIndicatorColor != value)
{
if (_MaxZoneIndicatorColor != null)
_MaxZoneIndicatorColor.ColorTableChanged -= KnobColorTableChanged;
_MaxZoneIndicatorColor = value;
if (_MaxZoneIndicatorColor != null)
_MaxZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMaxZoneIndicatorColor()
{
return (_MaxZoneIndicatorColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMaxZoneIndicatorColor()
{
MaxZoneIndicatorColor = LinearGradientColorTable.Empty;
}
#endregion
#region MidZoneIndicatorColor
/// <summary>
/// Gets or sets the color of the MidZoneIndicator
/// </summary>
[Browsable(true)]
[Description("Indicates the color of the MidZoneIndicator")]
public LinearGradientColorTable MidZoneIndicatorColor
{
get { return (_MidZoneIndicatorColor); }
set
{
if (_MidZoneIndicatorColor != value)
{
if (_MidZoneIndicatorColor != null)
_MidZoneIndicatorColor.ColorTableChanged -= KnobColorTableChanged;
_MidZoneIndicatorColor = value;
if (_MidZoneIndicatorColor != null)
_MidZoneIndicatorColor.ColorTableChanged += KnobColorTableChanged;
OnColorTableChange();
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeMidZoneIndicatorColor()
{
return (_MidZoneIndicatorColor.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public void ResetMidZoneIndicatorColor()
{
MidZoneIndicatorColor = LinearGradientColorTable.Empty;
}
#endregion
#region IsEmpty
[Browsable(false)]
public bool IsEmpty
{
get
{
return (_MajorTickColor.IsEmpty && _MinorTickColor.IsEmpty && _KnobIndicatorPointerColor.IsEmpty &&
_KnobFaceColor.IsEmpty && _ZoneIndicatorColor.IsEmpty && _MinZoneIndicatorColor.IsEmpty &&
_MaxZoneIndicatorColor.IsEmpty && _MidZoneIndicatorColor.IsEmpty && _KnobIndicatorColor.IsEmpty);
}
}
#endregion
#endregion
#region KnobColorTableChanged
/// <summary>
/// KnobColorTableChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void KnobColorTableChanged(object sender, EventArgs e)
{
OnColorTableChange();
}
#endregion
#region OnColorTableChange
/// <summary>
/// OnColorTableChange
/// </summary>
private void OnColorTableChange()
{
if (ColorTableChanged != null)
ColorTableChanged(this, EventArgs.Empty);
}
#endregion
}
#region KnobColorTableConvertor
/// <summary>
/// KnobColorTableConvertor
/// </summary>
public class KnobColorTableConvertor : ExpandableObjectConverter
{
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
KnobColorTable kct = value as KnobColorTable;
if (kct != null)
{
ColorConverter cvt = new ColorConverter();
string s;
if ((s = MyColorConverter(kct.KnobFaceColor, cvt)) != null)
return (s);
if ((s = MyColorConverter(kct.KnobIndicatorColor, cvt)) != null)
return (s);
if ((s = MyColorConverter(kct.MinZoneIndicatorColor, cvt)) != null)
return (s);
if ((s = MyColorConverter(kct.MidZoneIndicatorColor, cvt)) != null)
return (s);
if ((s = MyColorConverter(kct.MaxZoneIndicatorColor, cvt)) != null)
return (s);
if (kct.MinorTickColor.IsEmpty == false)
return (cvt.ConvertToString(kct.MinorTickColor));
if (kct.MajorTickColor.IsEmpty == false)
return (cvt.ConvertToString(kct.MajorTickColor));
if (kct.KnobIndicatorPointerColor.IsEmpty == false)
return (cvt.ConvertToString(kct.KnobIndicatorPointerColor));
if (kct.ZoneIndicatorColor.IsEmpty == false)
return (cvt.ConvertToString(kct.ZoneIndicatorColor));
return (String.Empty);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
#region MyColorConverter
/// <summary>
/// MyColorConverter
/// </summary>
/// <param name="ct">ColorTable</param>
/// <param name="cvt">ColorConverter</param>
/// <returns>string or null</returns>
private string MyColorConverter(LinearGradientColorTable ct, ColorConverter cvt)
{
if (ct.Start.IsEmpty == false)
return (cvt.ConvertToString(ct.Start));
if (ct.End.IsEmpty == false)
return (cvt.ConvertToString(ct.Start));
return (null);
}
#endregion
}
#endregion
}

View File

@@ -0,0 +1,36 @@
namespace DevComponents.Instrumentation
{
partial class KnobControl
{
/// <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,243 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation.Primitives
{
public class KnobStyle1 : BaseKnob
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="knobControl">Associated knob control</param>
public KnobStyle1(KnobControl knobControl)
: base(knobControl)
{
}
#region Knob Configuration
#region ConfigureKnob
/// <summary>
/// Configures the given knob control
/// by establishing various default object parameters
/// </summary>
/// <param name="e"></param>
public override void ConfigureKnob(PaintEventArgs e)
{
base.ConfigureKnob(e);
// Calculate default sizes and bounding object rectangles
ZoneIndWidth = 2;
MajorTickSize = new Size((int)(KnobWidth * 0.015), (int)(KnobWidth * 0.017));
MinorTickSize = new Size(MajorTickSize.Width / 2, MajorTickSize.Height);
IndTickHeight = (int)ZoneIndWidth;
CalculateBoundingRects();
// Fill in the default knob colors
DefaultColorTable.MajorTickColor = Color.Black;
DefaultColorTable.MinorTickColor = Color.Black;
DefaultColorTable.ZoneIndicatorColor = Color.Black;
DefaultColorTable.KnobIndicatorPointerColor = Color.Gray;
DefaultColorTable.KnobIndicatorPointerBorderColor = Color.Gray;
DefaultColorTable.KnobFaceColor = new LinearGradientColorTable(Color.Black, Color.Gray, 40);
DefaultColorTable.KnobIndicatorColor = new LinearGradientColorTable(Color.Gray, Color.White, 40);
DefaultColorTable.MinZoneIndicatorColor = new LinearGradientColorTable(Color.White, Color.Green);
DefaultColorTable.MaxZoneIndicatorColor = new LinearGradientColorTable(Color.Yellow, Color.Red);
}
#endregion
#region CalculateBoundingRects
/// <summary>
/// Calculates several default control
/// // bounding rectangles
/// </summary>
private void CalculateBoundingRects()
{
// Calculate the bounding Zone indicator rectangle and width
int delta = MaxLabelWidth + MajorTickSize.Height + (int)(KnobWidth * 0.04f);
ZoneIndicatorBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the KnobFace and inset face rectangles
delta += 1;
KnobFaceBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the KnobIndicator bounding rectangle
delta += (int)(KnobWidth * .07f);
KnobIndicatorBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the TickLabel bounding rect
delta = (int)((MaxLabelWidth + IndTickHeight) * .85f);
TickLabelBounds = new Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size);
TickLabelBounds.Inflate(delta, delta);
// Calculate the focus rectangle
FocusRectBounds = new Rectangle(KnobIndicatorBounds.Location, KnobIndicatorBounds.Size);
delta = (int)(KnobIndicatorBounds.Width * .035);
FocusRectBounds.Inflate(-delta, -delta);
}
#endregion
#endregion
#region Part rendering code
#region RenderZoneIndicator
/// <summary>
/// Renders the zone indicator
/// </summary>
/// <param name="e"></param>
public override void RenderZoneIndicator(PaintEventArgs e)
{
if (ZoneIndicatorBounds.Width > 10 && ZoneIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
using (Pen pen = new Pen(ZoneIndicatorColor, 2))
g.DrawEllipse(pen, ZoneIndicatorBounds);
}
}
#endregion
#region RenderKnobFace
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobFace(PaintEventArgs e)
{
if (KnobFaceBounds.Width > 10 && KnobFaceBounds.Height > 10)
{
Graphics g = e.Graphics;
using (Brush br = KnobFaceColor.GetBrush(KnobFaceBounds))
g.FillEllipse(br, KnobFaceBounds);
}
}
#endregion
#region RenderKnobIndicator
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobIndicator(PaintEventArgs e)
{
if (KnobIndicatorBounds.Width > 10 && KnobIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
// Render the Indicator shadow
Rectangle r = new Rectangle(KnobIndicatorBounds.X, KnobIndicatorBounds.Y,
KnobIndicatorBounds.Width, KnobIndicatorBounds.Height);
int delta = (int) (KnobWidth * .025f);
r.Offset(delta, delta);
using (SolidBrush br = new
SolidBrush(Color.FromArgb(160, KnobFaceColor.Start)))
{
g.FillEllipse(br, r);
}
r.Offset(-delta, -delta);
// Render the indicator
using (LinearGradientBrush br = new
LinearGradientBrush(KnobIndicatorBounds, KnobIndicatorColor.End, KnobIndicatorColor.Start, -40f))
g.FillEllipse(br, KnobIndicatorBounds);
delta = (int) (r.Width * .02f);
r.Inflate(-delta, -delta);
using (Brush br = KnobIndicatorColor.GetBrush(r))
g.FillEllipse(br, r);
// Render the indicator dimple
r = GetIndicatorRect();
delta = (int) (r.Width * .05f);
r.Inflate(delta, delta);
using (Brush lgb = new
LinearGradientBrush(r, Color.White, KnobIndicatorPointerColor, -40f))
{
g.FillEllipse(lgb, r);
}
r.Inflate(-delta, -delta);
using (LinearGradientBrush lgb = new
LinearGradientBrush(r, KnobIndicatorPointerColor, Color.White, 220f))
{
g.FillEllipse(lgb, r);
}
}
}
/// <summary>
/// Returns the knob indicator rectangle
/// </summary>
/// <returns></returns>
private Rectangle GetIndicatorRect()
{
float degrees = (float)(Knob.SweepAngle / ValueCount) *
(float)(Knob.Value - Knob.MinValue) + Knob.StartAngle;
double radians = GetRadians(degrees);
int dx = KnobIndicatorBounds.X + KnobIndicatorBounds.Width / 2;
int dy = KnobIndicatorBounds.Y + KnobIndicatorBounds.Height / 2;
int h = (int)(KnobIndicatorBounds.Width * .3f);
int x = (int)(Math.Cos(radians) * h + dx);
int y = (int)(Math.Sin(radians) * h + dy);
int radius = (int)(KnobIndicatorBounds.Width * .12f);
Rectangle r = new Rectangle(x - radius, y - radius, radius * 2, radius * 2);
return (r);
}
#endregion
#endregion
}
}

View File

@@ -0,0 +1,386 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation.Primitives
{
public class KnobStyle2 : BaseKnob
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="knobControl">Associated knob control</param>
public KnobStyle2(KnobControl knobControl)
: base(knobControl)
{
}
#region Knob Configuration
#region ConfigureKnob
/// <summary>
/// Configures the given knob control
/// by establishing various default object parameters
/// </summary>
/// <param name="e"></param>
public override void ConfigureKnob(PaintEventArgs e)
{
base.ConfigureKnob(e);
// Calculate default sizes and bounding object rectangles
ZoneIndWidth = KnobWidth * 0.047f;
MajorTickSize = new Size((int)(KnobWidth * 0.008), (int)(KnobWidth * 0.017));
MinorTickSize = new Size(1, (int)(KnobWidth * 0.02));
IndTickHeight = (int)ZoneIndWidth / 3;
CalculateBoundingRects();
// Fill in the default knob colors
DefaultColorTable.MajorTickColor = Color.Black;
DefaultColorTable.MinorTickColor = Color.Gray;
DefaultColorTable.ZoneIndicatorColor = Color.SteelBlue;
DefaultColorTable.KnobIndicatorPointerColor = Color.Black;
DefaultColorTable.KnobIndicatorPointerBorderColor = Color.Black;
DefaultColorTable.KnobFaceColor = new LinearGradientColorTable(Color.White, Color.LightGray);
DefaultColorTable.KnobIndicatorColor = new LinearGradientColorTable(0xFFFFFF, 0x1A507B);
DefaultColorTable.MinZoneIndicatorColor = new LinearGradientColorTable(Color.White, Color.Green);
DefaultColorTable.MaxZoneIndicatorColor = new LinearGradientColorTable(Color.Yellow, Color.Red);
}
#endregion
#region CalculateBoundingRects
/// <summary>
/// Calculates several default control
/// // bounding rectangles
/// </summary>
private void CalculateBoundingRects()
{
// Calculate the bounding Zone indicator rectangle and width
int delta = MaxLabelWidth + MajorTickSize.Height + (int)(KnobWidth * 0.05f);
ZoneIndicatorBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the KnobFace and inset face rectangles
delta += (int)ZoneIndWidth + 1;
KnobFaceBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the KnobIndicator bounding rectangle
delta += (int)(KnobWidth * .068f);
KnobIndicatorBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the TickLabel bounding rect
delta = (int)((MaxLabelWidth + IndTickHeight) * .60f + IndTickHeight);
TickLabelBounds = new Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size);
TickLabelBounds.Inflate(delta, delta);
// Calculate the focus rectangle
FocusRectBounds = new Rectangle(KnobFaceBounds.Location, KnobFaceBounds.Size);
delta = (int)(KnobFaceBounds.Width * .025);
FocusRectBounds.Inflate(-delta, -delta);
}
#endregion
#endregion
#region Part rendering code
#region RenderZoneIndicator
/// <summary>
/// Renders the zone indicator
/// </summary>
/// <param name="e"></param>
public override void RenderZoneIndicator(PaintEventArgs e)
{
if (ZoneIndicatorBounds.Width > 10 && ZoneIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
Color c = ControlPaint.Light(ZoneIndicatorColor, .30f);
int passes = (int) (ZoneIndWidth);
int adj = 100 / passes;
Rectangle r = new Rectangle(ZoneIndicatorBounds.X,
ZoneIndicatorBounds.Y, ZoneIndicatorBounds.Width, ZoneIndicatorBounds.Height);
r.Inflate(-passes, -passes);
for (int i = 0; i < passes; i++)
{
using (Pen pen = new Pen(c, 2))
{
g.DrawEllipse(pen, r);
r.Inflate(1, 1);
c = Color.FromArgb(Math.Max(0, c.R - adj),
Math.Max(0, c.G - adj), Math.Max(0, c.B - adj));
}
}
}
}
#endregion
#region RenderTickMinor
/// <summary>
/// Renders the minor tick marks
/// </summary>
/// <param name="e"></param>
public override void RenderTickMinor(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen pen = new Pen(MinorTickColor, MinorTickSize.Width))
{
for (int i = 0; i < MinorTicks; i++)
{
// Don't draw a minor tick if it overlaps
// with a previous major tick
if (Knob.MajorTickAmount > 0)
{
if ((i == 0 || i == MinorTicks - 1) ||
((Knob.MinorTickAmount * i) % Knob.MajorTickAmount == 0))
continue;
}
g.DrawLines(pen, GetMinorTickPoints(i));
}
}
}
/// <summary>
/// Calculates a series of points
/// that defines the tick mark
/// </summary>
/// <param name="tick">Tick to calculate</param>
/// <returns>An array of points that defines the tick</returns>
private Point[] GetMinorTickPoints(int tick)
{
float degree = GetTickDegree((float)Knob.MinorTickAmount, tick);
double rad = GetRadians(degree);
int dx = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int dy = ZoneIndicatorBounds.Y + ZoneIndicatorBounds.Height / 2;
int h = (int)(ZoneIndicatorBounds.Width / 2 + ZoneIndWidth * .1f);
Point[] pts = new Point[2];
pts[0].X = (int)(Math.Cos(rad) * h + dx);
pts[0].Y = (int)(Math.Sin(rad) * h + dy);
pts[1].X = (int)(Math.Cos(rad) * (h + MinorTickSize.Height) + dx);
pts[1].Y = (int)(Math.Sin(rad) * (h + MinorTickSize.Height) + dy);
return (pts);
}
#endregion
#region RenderKnobFace
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobFace(PaintEventArgs e)
{
if (KnobFaceBounds.Width > 10 && KnobFaceBounds.Height > 10)
{
Graphics g = e.Graphics;
// Allocate a path to accumulate the knob
// drawing pieces
using (GraphicsPath path = new GraphicsPath())
{
// Draw the 14 arc segments all the way to the
// center of the knob just in case the user wants
// to render a different sized/shaped knob indicator
Rectangle rInset = new Rectangle(KnobFaceBounds.X, KnobFaceBounds.Y,
KnobFaceBounds.Width, KnobFaceBounds.Height);
int w = KnobFaceBounds.Width/2 - 1;
rInset.Inflate(-w, -w);
const float arc = 360f/14;
for (int i = 0; i < 14; i++)
{
if (i%2 == 0)
{
path.AddArc(KnobFaceBounds, i*arc, arc);
path.AddArc(rInset, (i + 1)*arc, -arc);
// Let Windows connect the arcs
path.CloseFigure();
}
}
// Select an appropriate hatch size given
// the overall size of the control
HatchStyle hs = (KnobWidth < 250)
? HatchStyle.LightUpwardDiagonal
: HatchStyle.WideUpwardDiagonal;
// Fill the face and then draw the outlining path
using (HatchBrush hbr = new HatchBrush(hs, KnobFaceColor.Start, KnobFaceColor.End))
g.FillPath(hbr, path);
using (Pen pen = new Pen(KnobFaceColor.End))
g.DrawPath(pen, path);
}
}
}
#endregion
#region RenderKnobIndicator
#region RenderKnobIndicator
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobIndicator(PaintEventArgs e)
{
if (KnobIndicatorBounds.Width > 10 && KnobIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
// Allocate a graphics path and draw the
// arrow lines into it
using (GraphicsPath path = new GraphicsPath())
{
path.AddLines(GetIndicatorPoints());
path.CloseFigure();
// Fill the closed arrow
using (SolidBrush br = new SolidBrush(KnobIndicatorPointerColor))
g.FillPath(br, path);
// Outline the arrow and draw the knob face
if (KnobIndicatorPointerBorderWidth > 0 &&
KnobIndicatorPointerColor.Equals(KnobIndicatorPointerBorderColor) == false)
{
using (Pen pen = new Pen(KnobIndicatorPointerBorderColor, KnobIndicatorPointerBorderWidth))
g.DrawPath(pen, path);
}
// Fill the knob face
using (Brush br = KnobIndicatorColor.GetBrush(KnobIndicatorBounds))
g.FillEllipse(br, KnobIndicatorBounds);
// Reset the path and add a glossy looking
// hilight to the control face
path.Reset();
path.AddEllipse(KnobIndicatorBounds);
using (PathGradientBrush pgb = new PathGradientBrush(path))
{
pgb.CenterColor = KnobIndicatorColor.Start;
pgb.SurroundColors = new Color[] {KnobIndicatorColor.End};
int radius = KnobIndicatorBounds.Width/2;
int dr = Math.Max((int) (radius*.1f), 5);
float dx = (radius - dr)*(float) Math.Sin(GetRadians(60));
float dy = (radius - dr)*(float) Math.Cos(GetRadians(60));
pgb.CenterPoint = new PointF(KnobIndicatorBounds.X + radius - dx,
KnobIndicatorBounds.Y + radius - dy);
g.FillRectangle(pgb, KnobIndicatorBounds);
}
}
}
}
#endregion
#region GetIndicatorPoints
/// <summary>
/// Calculates a series of points that
/// defines the indicator arrow
/// </summary>
/// <returns>An array of defining points</returns>
private Point[] GetIndicatorPoints()
{
float degrees = (float)(Knob.SweepAngle / ValueCount) *
(float)(Knob.Value - Knob.MinValue) + Knob.StartAngle;
int arrowHeight = (int)(KnobWidth * .052f);
double rad0 = GetRadians(degrees - 17);
double rad1 = GetRadians(degrees);
double rad2 = GetRadians(degrees + 17);
int n = (int)(KnobIndicatorBounds.Width * .03f);
if (n < 2)
n = 2;
int dx = KnobIndicatorBounds.X + KnobIndicatorBounds.Width / 2 + 1;
int dy = KnobIndicatorBounds.Y + KnobIndicatorBounds.Height / 2 + 1;
int h = KnobIndicatorBounds.Width / 2 + n;
Point[] pts = new Point[3];
pts[0].X = (int)(Math.Cos(rad0) * h + dx);
pts[0].Y = (int)(Math.Sin(rad0) * h + dy);
pts[1].X = (int)(Math.Cos(rad1) * (h + arrowHeight) + dx);
pts[1].Y = (int)(Math.Sin(rad1) * (h + arrowHeight) + dy);
pts[2].X = (int)(Math.Cos(rad2) * h + dx);
pts[2].Y = (int)(Math.Sin(rad2) * h + dy);
return (pts);
}
#endregion
#endregion
#endregion
}
}

View File

@@ -0,0 +1,776 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.Instrumentation.Primitives
{
public class KnobStyle3 : BaseKnob
{
/// <summary>
/// Constructor
/// </summary>
/// <param name="knobControl">Associated knob control</param>
public KnobStyle3(KnobControl knobControl)
: base(knobControl)
{
}
#region Knob Configuration
#region ConfigureKnob
/// <summary>
/// Configures the given knob control
/// by establishing various default object parameters
/// </summary>
/// <param name="e"></param>
public override void ConfigureKnob(PaintEventArgs e)
{
base.ConfigureKnob(e);
// Calculate default sizes and bounding object rectangles
ZoneIndWidth = KnobWidth * 0.034f;
MajorTickSize = new Size((int)(KnobWidth * 0.018), (int)(KnobWidth * 0.05));
MinorTickSize = new Size(MajorTickSize.Width / 2, MajorTickSize.Height);
IndTickHeight = MajorTickSize.Height / 3;
CalculateBoundingRects();
// Fill in the default knob colors
DefaultColorTable.MajorTickColor = Color.Black;
DefaultColorTable.MinorTickColor = Color.Black;
DefaultColorTable.ZoneIndicatorColor = Color.Black;
DefaultColorTable.KnobIndicatorPointerColor = Color.Black;
DefaultColorTable.KnobIndicatorPointerBorderColor = Color.Gray;
DefaultColorTable.KnobFaceColor = new LinearGradientColorTable(Color.Goldenrod, Color.Goldenrod, 40);
DefaultColorTable.KnobIndicatorColor = new LinearGradientColorTable(Color.White, Color.LightGray);
DefaultColorTable.MinZoneIndicatorColor = new LinearGradientColorTable(Color.White, Color.Green);
DefaultColorTable.MaxZoneIndicatorColor = new LinearGradientColorTable(Color.Yellow, Color.Red);
DefaultColorTable.MidZoneIndicatorColor = new LinearGradientColorTable(Color.CornflowerBlue);
}
#endregion
#region CalculateBoundingRects
/// <summary>
/// Calculates several default control
/// // bounding rectangles
/// </summary>
private void CalculateBoundingRects()
{
// Calculate the bounding Zone indicator rectangle and width
int delta = MaxLabelWidth + MajorTickSize.Height;
ZoneIndicatorBounds = new Rectangle(delta, delta,
KnobWidth - (delta * 2), KnobWidth - (delta * 2));
// Calculate the KnobFace and inset face rectangles
delta = (int)(ZoneIndicatorBounds.Width * .025f + ZoneIndWidth);
KnobFaceBounds = ZoneIndicatorBounds;
KnobFaceBounds.Inflate(-delta, -delta);
// Calculate the KnobIndicator bounding rectangle
delta = (int)(ZoneIndicatorBounds.Width * .14f);
KnobIndicatorBounds = ZoneIndicatorBounds;
KnobIndicatorBounds.Inflate(-delta, -delta);
// Calculate the TickLabel bounding rect
delta = (int)((MaxLabelWidth + IndTickHeight) * .60f);
TickLabelBounds = new Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size);
TickLabelBounds.Inflate(delta, delta);
// Calculate the focus rectangle
FocusRectBounds = KnobIndicatorBounds;
delta = (int)(KnobIndicatorBounds.Width * .025);
FocusRectBounds.Inflate(-delta, -delta);
}
#endregion
#endregion
#region Part rendering code
#region RenderZoneIndicator
#region RenderZoneIndicator
/// <summary>
/// Renders the zone indicator
/// </summary>
/// <param name="e"></param>
public override void RenderZoneIndicator(PaintEventArgs e)
{
if (ZoneIndicatorBounds.Width > 10 && ZoneIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
int leftEndAngle = Knob.StartAngle;
int rightStartAngle = Knob.StartAngle;
// Render the left zone - if present
if (Knob.MinZonePercentage > 0)
{
float pct = Knob.MinZonePercentage / 100f;
RenderArc(g, Knob.StartAngle,
Knob.SweepAngle * pct, LeftZoneIndicatorColor);
leftEndAngle = (int)(Knob.StartAngle + Knob.SweepAngle * pct);
}
// Render the right-hand zone - if present
if (Knob.MaxZonePercentage > 0)
{
float pct = Knob.MaxZonePercentage / 100f;
RenderArc(g, Knob.StartAngle + Knob.SweepAngle * (1 - pct),
Knob.SweepAngle * pct, RightZoneIndicatorColor);
rightStartAngle = (int)(Knob.StartAngle + Knob.SweepAngle * (1 - pct));
}
// Render the middle zone
if (rightStartAngle != leftEndAngle)
{
RenderArc(g, leftEndAngle,
rightStartAngle - leftEndAngle, MiddleZoneIndicatorColor);
}
}
}
#endregion
#region RenderArc
/// <summary>
/// Renders a gradient indicator arc by dividing
/// the arc into sub-arcs, enabling us to utilize normal
/// rectangle gradient support
/// </summary>
/// <param name="g"></param>
/// <param name="a1">Starting angle</param>
/// <param name="s1">Sweep angle</param>
/// <param name="ct"></param>
private void RenderArc(Graphics g, float a1, float s1, LinearGradientColorTable ct)
{
float n1 = Math.Abs(s1);
Color c1 = ct.Start;
Color c2 = ct.End.IsEmpty == false ? ct.End : ct.Start;
// Calculate our rect and inflate to
// make room for the indicator arc
Rectangle rect = new
Rectangle(ZoneIndicatorBounds.Location, ZoneIndicatorBounds.Size);
int dw = (int)(ZoneIndWidth / 2);
rect.Inflate(-dw, -dw);
// Calculate the RGB color deltas
float dr = (c2.R - c1.R) / n1;
float dg = (c2.G - c1.G) / n1;
float db = (c2.B - c1.B) / n1;
// Set our initial starting color and range
Color c3 = Color.FromArgb(c1.ToArgb());
float s2 = s1;
float a2 = a1;
int pa = (s1 > 0) ? 100 : -100;
// Loop through the arc, processing sub-arcs less
// than 180 degrees so that we can use GDI+ built-in
// gradient rectangle support
while (s2 != 0)
{
// Limit our sweep angle pass to 90 degrees
float sw = (s2 > 0) ?
Math.Min(s2, 90) : Math.Max(s2, -90);
// Calculate our sub-sweep angle points. This
// enables us to create an associated bounding
// rectangle for the sub-sweep arc
Point pt1 = CalcCoord(a2);
Point pt2 = CalcCoord(a2 + sw);
Rectangle r = new Rectangle();
r.Location = new Point(Math.Min(pt1.X, pt2.X), Math.Min(pt1.Y, pt2.Y));
r.Size = new Size(Math.Abs(pt1.X - pt2.X), Math.Abs(pt1.Y - pt2.Y));
if (r.Width == 0)
r.Width = 1;
if (r.Height == 0)
r.Height = 1;
// Calculate the terminal color for the
// sub-sweep arc
float n = Math.Abs(sw);
int red = (int)(c3.R + n * dr);
red = Math.Max(Math.Min(red, 255), 0);
int green = (int)(c3.G + n * dg);
green = Math.Max(Math.Min(green, 255), 0);
int blue = (int)(c3.B + n * db);
blue = Math.Max(Math.Min(blue, 255), 0);
Color c4 = Color.FromArgb(red, green, blue);
// Tally up this sub-sweep
s2 -= sw;
// Render the sub-arc with an appropriately
// orientated gradient brush, and draw the arc
using (LinearGradientBrush lbr = new LinearGradientBrush(r, c3, c4, a2 + pa))
{
using (Pen pen = new Pen(lbr, (int)ZoneIndWidth))
g.DrawArc(pen, rect, a2, sw);
}
// Bump up our starting angle to reflect the
// processing of this sub-arc
a2 += sw;
// Set the next starting color to the
// ending color for this arc
c3 = c4;
}
// Render the bounding indicator arcs
using (GraphicsPath p1 = new GraphicsPath())
{
rect.Inflate(-dw, -dw);
p1.AddArc(ZoneIndicatorBounds, a1, s1);
p1.AddArc(rect, a1 + s1, -s1);
// Let Windows close the arcs, and then
// render them
p1.CloseFigure();
using (Pen pen = new Pen(ZoneIndicatorColor, MinorTickSize.Width))
g.DrawPath(pen, p1);
}
}
#endregion
#region CalcCoord
/// <summary>
/// Calculates the arc coordinates for
/// a given angle
/// </summary>
/// <param name="a2">Angle</param>
/// <returns></returns>
private Point CalcCoord(float a2)
{
Point pt = new Point();
// Normalize the angle and calculate some
// working vars
if (a2 < 0)
a2 += 360;
a2 = a2 % 360;
int delta = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int radius = ZoneIndicatorBounds.Width / 2;
int d = (int)(ZoneIndWidth / 2);
// Determine the angle quadrant, and then calculate
// the intersecting coordinate accordingly
if (a2 < 90)
{
pt.X = (int)(Math.Cos(GetRadians(a2 % 90)) * (radius + d));
pt.Y = (int)(Math.Sin(GetRadians(a2 % 90)) * (radius + d));
}
else if (a2 < 180)
{
pt.X = -(int)(Math.Sin(GetRadians(a2 % 90)) * (radius + d));
pt.Y = (int)(Math.Cos(GetRadians(a2 % 90)) * (radius + d));
}
else if (a2 < 270)
{
pt.X = -(int)(Math.Cos(GetRadians(a2 % 90)) * (radius + d));
pt.Y = -(int)(Math.Sin(GetRadians(a2 % 90)) * (radius + d));
}
else
{
pt.X = (int)(Math.Sin(GetRadians(a2 % 90)) * (radius + d));
pt.Y = -(int)(Math.Cos(GetRadians(a2 % 90)) * (radius + d));
}
// Adjust the point to the intersecting arc
pt.X += delta;
pt.Y += delta;
return (pt);
}
#endregion
#endregion
#region RenderTickMinor
#region RenderTickMinor
/// <summary>
/// Renders the minor tick marks
/// </summary>
/// <param name="e"></param>
public override void RenderTickMinor(PaintEventArgs e)
{
Graphics g = e.Graphics;
using (Pen pen = new Pen(MinorTickColor, MinorTickSize.Width))
{
for (int i = 0; i < MinorTicks; i++)
{
// Don't draw a minor tick if it overlaps
// with a previous major tick
if (Knob.MajorTickAmount > 0)
{
if ((i == 0 || i == MinorTicks - 1) ||
((Knob.MinorTickAmount * i) % Knob.MajorTickAmount == 0))
continue;
}
g.DrawLines(pen, GetMinorTickPoints(i));
}
}
}
#endregion
#region GetMinorTickPoints
/// <summary>
/// Calculates a series of points
/// that defines the tick mark
/// </summary>
/// <param name="tick">Tick to calculate</param>
/// <returns>An array of points that defines the tick</returns>
private Point[] GetMinorTickPoints(int tick)
{
float degree = GetTickDegree((float)Knob.MinorTickAmount, tick);
double rad = GetRadians(degree);
int dx = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int dy = ZoneIndicatorBounds.Y + ZoneIndicatorBounds.Height / 2;
int h = ZoneIndicatorBounds.Width / 2 - (int)ZoneIndWidth;
Point[] pts = new Point[2];
pts[0].X = (int)(Math.Cos(rad) * (h) + dx);
pts[0].Y = (int)(Math.Sin(rad) * (h) + dy);
pts[1].X = (int)(Math.Cos(rad) * (h + MinorTickSize.Height) + dx);
pts[1].Y = (int)(Math.Sin(rad) * (h + MinorTickSize.Height) + dy);
return (pts);
}
#endregion
#endregion
#region RenderTickMajor
#region RenderTickMajor
/// <summary>
/// Renders the Major Tick marks
/// </summary>
/// <param name="e"></param>
public override void RenderTickMajor(PaintEventArgs e)
{
Graphics g = e.Graphics;
// Loop through each tick
using (Pen pen1 = new Pen(MajorTickColor, MajorTickSize.Width))
{
for (int i = 0; i < MajorTicks; i++)
g.DrawLines(pen1, GetMajorTickPoints(i));
}
}
#endregion
#region GetMajorTickPoints
/// <summary>
/// Calculates a series of points
/// that defines the tick mark
/// </summary>
/// <param name="tick">Tick to calculate</param>
/// <returns>An array of points that defines the tick</returns>
private Point[] GetMajorTickPoints(int tick)
{
float degree = GetTickDegree((float)Knob.MajorTickAmount, tick);
double rad = GetRadians(degree);
int dx = ZoneIndicatorBounds.X + ZoneIndicatorBounds.Width / 2;
int dy = ZoneIndicatorBounds.Y + ZoneIndicatorBounds.Height / 2;
int h = ZoneIndicatorBounds.Width / 2 - (int)ZoneIndWidth;
Point[] pts = new Point[2];
pts[0].X = (int)(Math.Cos(rad) * h + dx);
pts[0].Y = (int)(Math.Sin(rad) * h + dy);
pts[1].X = (int)(Math.Cos(rad) * (h + MajorTickSize.Height + 1) + dx);
pts[1].Y = (int)(Math.Sin(rad) * (h + MajorTickSize.Height + 1) + dy);
return (pts);
}
#endregion
#endregion
#region RenderKnobFace
#region RenderKnobFace
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobFace(PaintEventArgs e)
{
if (KnobFaceBounds.Width > 10 && KnobFaceBounds.Height > 10)
{
Graphics g = e.Graphics;
// Allocate a path to accumulate the knob
// drawing pieces
using (GraphicsPath path = new GraphicsPath())
{
// Render the face shadow
RenderInset(g, path, Pens.Gray, MinorTickSize.Width);
using (SolidBrush br =
new SolidBrush(Color.FromArgb(160, Color.Gray)))
{
g.FillPath(br, path);
}
path.Reset();
// Render the face front
using (Pen pen = new Pen(Color.White, MinorTickSize.Width))
RenderInset(g, path, pen, 0);
using (Brush br = KnobFaceColor.GetBrush(KnobFaceBounds))
g.FillPath(br, path);
}
}
}
#endregion
#region RenderInset
/// <summary>
/// Renders the face, including the arc insets
/// as well as the connecting segments
/// </summary>
/// <param name="g"></param>
/// <param name="path">Path to render to</param>
/// <param name="pen">Outlining pen</param>
/// <param name="offset">Delta offset - used for shadowing</param>
private void RenderInset(Graphics g, GraphicsPath path, Pen pen, int offset)
{
// Calculate the bounding rectangle
// for the inset segments
Rectangle rInset = KnobFaceBounds;
int w = (int)(ZoneIndWidth);
rInset.Inflate(-w, -w);
// Calculate the bounding rectangle
// for the inset arcs
int radius = (int)(KnobWidth * .055f);
Rectangle r = new Rectangle(0, 0, radius, radius);
// Loop through each arc point and
// render the individual arc insets
for (int i = 0; i < 12; i++)
{
// Calculate the inset location and
// render the inset arc
r.Location = GetArcPoint(rInset, i * 30f, (int)(offset - radius * .5f));
path.AddArc(r, (i * 30) - 90, -180);
}
// Let Windows connect the arcs, and
// then draw the completed path
path.CloseFigure();
g.DrawPath(pen, path);
}
#endregion
#region GetArcPoint
/// <summary>
/// Calculates the arc point at the given
/// degree and offset
/// </summary>
/// <param name="rInset">Inset bounding rectangle</param>
/// <param name="degree">Degree to position arc inset</param>
/// <param name="offset">Offset (used for shading)</param>
/// <returns></returns>
private Point GetArcPoint(Rectangle rInset, float degree, int offset)
{
// Calculate the default position
double rad = GetRadians(degree);
int dx = rInset.X + rInset.Width / 2;
int dy = rInset.Y + rInset.Height / 2;
int h = rInset.Width / 2 + (int)ZoneIndWidth;
Point pt = new Point();
pt.X = (int)(Math.Cos(rad) * h + dx);
pt.Y = (int)(Math.Sin(rad) * h + dy);
// Offset the point if so requested
// (face shadow support)
pt.Offset(offset, offset);
return (pt);
}
#endregion
#endregion
#region RenderKnobIndicator
#region RenderKnobIndicator
/// <summary>
/// Renders the knob face
/// </summary>
/// <param name="e"></param>
public override void RenderKnobIndicator(PaintEventArgs e)
{
if (KnobIndicatorBounds.Width > 10 && KnobIndicatorBounds.Height > 10)
{
Graphics g = e.Graphics;
// Allocate a graphics path and calculate
// its bounding rectangle
using (GraphicsPath path = new GraphicsPath())
{
Rectangle r = new
Rectangle(KnobIndicatorBounds.Location, KnobIndicatorBounds.Size);
int delta = (int) (KnobWidth*.020f);
// Render the knob, it's shadow, and
// the hilight crescent
r.Offset(delta, delta);
RenderIndFace(g, path, r);
r.Offset(-delta*2, -delta*2);
RenderIndCrescent(g, path, r);
// Render the indicator arrow
path.AddLines(GetIndicatorPoints());
path.CloseFigure();
// Fill the closed arrow
using (SolidBrush br = new SolidBrush(KnobIndicatorPointerColor))
{
g.FillPath(br, path);
// Outline the arrow
if (KnobIndicatorPointerBorderWidth > 0 &&
KnobIndicatorPointerColor.Equals(KnobIndicatorPointerBorderColor) == false)
{
using (Pen pen = new Pen(KnobIndicatorPointerBorderColor, KnobIndicatorPointerBorderWidth))
g.DrawPath(pen, path);
}
}
}
}
}
#endregion
#region RenderIndCrescent
/// <summary>
/// Renders the hilight crescent
/// </summary>
/// <param name="g"></param>
/// <param name="path">Accumulating GraphicsPath</param>
/// <param name="r">Bounding rectangle</param>
private void RenderIndCrescent(Graphics g, GraphicsPath path, Rectangle r)
{
// Add the bottom crescent arc
path.AddArc(r, 8, 78);
// Calculate the intersecting upper arc
// and add it to the path
int cradius = r.Width / 2;
int nradius = (int)(cradius * 1.5f);
int dr = nradius - cradius;
int dz = (int)(dr * Math.Cos(45) * 1.6f);
Rectangle r2 = new Rectangle(r.X - dr - dz, r.Y - dr - dz, nradius * 2, nradius * 2);
path.AddArc(r2, 70, -50);
Color c = Color.FromArgb(170, KnobIndicatorColor.Start);
using (LinearGradientBrush lbr =
new LinearGradientBrush(KnobIndicatorBounds, Color.White, c, 45f))
{
g.FillPath(lbr, path);
}
path.Reset();
}
#endregion
#region RenderIndFace
/// <summary>
/// Renders the face of the knob indicator
/// </summary>
/// <param name="g"></param>
/// <param name="path">Accumulating GraphicsPath</param>
/// <param name="r">Bounding rectangle</param>
private void RenderIndFace(Graphics g, GraphicsPath path, Rectangle r)
{
// Render the knob shadow
Color c3 = Color.FromArgb(100, ControlPaint.Dark(KnobIndicatorColor.End));
using (SolidBrush br = new SolidBrush(c3))
g.FillEllipse(br, r);
// Render the knob
using (Brush br = KnobIndicatorColor.GetBrush(KnobIndicatorBounds))
g.FillEllipse(br, KnobIndicatorBounds);
path.Reset();
}
#endregion
#region GetIndicatorPoints
/// <summary>
/// Calculates a series of points that
/// defines the indicator arrow
/// </summary>
/// <returns>An array of defining points</returns>
private Point[] GetIndicatorPoints()
{
float degrees = (float)(Knob.SweepAngle / ValueCount) *
(float)(Knob.Value - Knob.MinValue) + Knob.StartAngle;
int arrowHeight = (int)(KnobWidth * .025f);
double rad0 = GetRadians(degrees - 19);
double rad1 = GetRadians(degrees);
double rad2 = GetRadians(degrees + 19);
int dx = KnobIndicatorBounds.X + KnobIndicatorBounds.Width / 2 + 1;
int dy = KnobIndicatorBounds.Y + KnobIndicatorBounds.Height / 2 + 1;
int h = KnobIndicatorBounds.Width / 2;
Point[] pts = new Point[3];
pts[0].X = (int)(Math.Cos(rad0) * h + dx);
pts[0].Y = (int)(Math.Sin(rad0) * h + dy);
pts[1].X = (int)(Math.Cos(rad1) * (h + arrowHeight) + dx);
pts[1].Y = (int)(Math.Sin(rad1) * (h + arrowHeight) + dy);
pts[2].X = (int)(Math.Cos(rad2) * h + dx);
pts[2].Y = (int)(Math.Sin(rad2) * h + dy);
return (pts);
}
#endregion
#endregion
#endregion
}
}

Some files were not shown because too many files have changed in this diff Show More