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,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
}