using System;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Globalization;
using DevComponents.DotNetBar.Charts.Primitives;
namespace DevComponents.DotNetBar.Charts.Style
{
///
/// Represents background of visual style.
///
[TypeConverter(typeof(BackgroundConvertor))]
[Editor(typeof(BackgroundEditor), typeof(UITypeEditor))]
public class Background : INotifyPropertyChanged, IDisposable, IProcessSerialElement
{
#region Static data
///
/// Empty
///
///
/// Returns Empty instance of Background.
///
public static Background Empty
{
get { return (new Background()); }
}
#endregion
#region Private variables
private Color _Color1 = Color.Empty;
private Color _Color2 = Color.Empty;
private int _GradientAngle = 90;
private double _RadialCenter = 0.0d;
private BackFillType _BackFillType = BackFillType.Angle;
private HatchFillType _HatchFillType = HatchFillType.NotSet;
private BackColorBlend _BackColorBlend;
#endregion
#region Constructors
///
/// Creates new instance of the object.
///
public Background() { }
///
/// Creates new instance of the object.
///
/// Start color.
public Background(Color color1)
{
_Color1 = color1;
}
///
/// Creates new instance of the object.
///
/// Start color.
/// End color.
public Background(Color color1, Color color2)
{
_Color1 = color1;
_Color2 = color2;
}
///
/// Creates new instance of the object.
///
/// Start color in hexadecimal representation like FFFFFF.
/// End color in hexadecimal representation like FFFFFF.
public Background(string color1, string color2)
{
_Color1 = ColorFactory.GetColor(color1);
_Color2 = ColorFactory.GetColor(color2);
}
///
/// Creates new instance of the object.
///
/// Start color in 32-bit RGB representation.
/// End color in 32-bit RGB representation.
public Background(int color1, int color2)
{
_Color1 = ColorFactory.GetColor(color1);
_Color2 = ColorFactory.GetColor(color2);
}
///
/// Creates new instance of the object.
///
/// Start color in 32-bit RGB representation.
/// End color in 32-bit RGB representation.
/// Gradient angle.
public Background(int color1, int color2, int gradientAngle)
{
_Color1 = ColorFactory.GetColor(color1);
_Color2 = ColorFactory.GetColor(color2);
GradientAngle = gradientAngle;
}
///
/// Creates new instance of the object.
///
/// Start color.
/// End color.
/// Gradient angle.
public Background(Color color1, Color color2, int gradientAngle)
{
_Color1 = color1;
_Color2 = color2;
GradientAngle = gradientAngle;
}
///
/// Creates new instance of the object.
///
/// Start color.
/// End color.
/// Gradient angle.
public Background(Color color1, Color color2, BackFillType fillType)
{
_Color1 = color1;
_Color2 = color2;
_BackFillType = fillType;
}
#endregion
#region Public properties
#region BackColorBlend
///
/// Gets or sets the BackColorBlend.
///
[Description("Indicates the BackColorBlend.")]
public BackColorBlend BackColorBlend
{
get
{
if (_BackColorBlend == null)
{
_BackColorBlend = new BackColorBlend();
UpdateChangeHandler(null, _BackColorBlend);
}
return (_BackColorBlend);
}
set
{
if (_BackColorBlend != value)
{
UpdateChangeHandler(_BackColorBlend, value);
_BackColorBlend = value;
OnPropertyChangedEx("BackColorBlend");
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeBackColorBlend()
{
return (_BackColorBlend != null && _BackColorBlend.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetBackColorBlend()
{
BackColorBlend = null;
}
#endregion
#region BackFillType
///
/// Gets or sets the Gradient BackFillType
///
[DefaultValue(BackFillType.Angle)]
[Description("Indicates the Gradient BackFillType.")]
public BackFillType BackFillType
{
get { return (_BackFillType); }
set
{
if (_BackFillType != value)
{
_BackFillType = value;
OnPropertyChangedEx("BackFillType");
}
}
}
#endregion
#region Color1
///
/// Gets or sets the start color.
///
[Description("Indicates the Starting Gradient Color.")]
public Color Color1
{
get { return (_Color1); }
set
{
if (_Color1 != value)
{
_Color1 = value;
OnPropertyChangedEx("Color1");
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeColor1()
{
return (_Color1.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetColor1()
{
Color1 = Color.Empty;
}
#endregion
#region Color2
///
/// Gets or sets the Ending Gradient Color
///
[Description("Indicates the Ending Gradient Color")]
public Color Color2
{
get { return (_Color2); }
set
{
if (_Color2 != value)
{
_Color2 = value;
OnPropertyChangedEx("Color2");
}
}
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual bool ShouldSerializeColor2()
{
return (_Color2.IsEmpty == false);
}
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
internal virtual void ResetColor2()
{
Color2 = Color.Empty;
}
#endregion
#region GradientAngle
///
/// Gets or sets the gradient angle (default is 90)
///
[DefaultValue(90)]
[Description("Indicates the Gradient Angle default is 90)")]
public int GradientAngle
{
get { return (_GradientAngle); }
set
{
if (_GradientAngle != value)
{
_GradientAngle = value;
OnPropertyChangedEx("GradientAngle");
}
}
}
#endregion
#region HatchFillType
///
/// Gets or sets the Gradient BackFillType
///
[DefaultValue(HatchFillType.NotSet)]
[Description("Indicates the Hatch FillType.")]
public HatchFillType HatchFillType
{
get { return (_HatchFillType); }
set
{
if (_HatchFillType != value)
{
_HatchFillType = value;
OnPropertyChangedEx("HatchFillType");
}
}
}
#endregion
#region RadialCenter
///
/// Gets or sets the Radial Gradient Center expressed as a percentage of the radius (from 0 to 1)
///
[DefaultValue(0.0d)]
[Description("Indicates the Radial Gradient Center expressed as a percentage of the radius (om 0 to 1)")]
public double RadialCenter
{
get { return (_RadialCenter); }
set
{
if (_RadialCenter != value)
{
if (value < 0 || value > 1)
throw new Exception("RadialCenter must be a value between 0 and 1");
_RadialCenter = value;
OnPropertyChangedEx("RadialCenter");
}
}
}
#endregion
#region IsSolidBrush
///
/// Gets whether the backcolor brush is a SolidBrush
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsSolidBrush
{
get
{
if (_BackColorBlend != null && _BackColorBlend.IsEmpty == false)
{
if (_BackColorBlend.Colors.Length == 1)
return (true);
}
if (_Color2.IsEmpty == true)
return (true);
return (false);
}
}
#endregion
#region IsEmpty
///
/// Gets whether Background is empty.
///
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsEmpty
{
get
{
return ((_BackColorBlend == null || _BackColorBlend.IsEmpty) &&
(_BackFillType == BackFillType.Angle) &&
(_Color1.IsEmpty == true) &&
(_Color2.IsEmpty == true) &&
(_GradientAngle == 90) &&
(_HatchFillType == HatchFillType.NotSet) &&
(_RadialCenter == .0));
}
}
#endregion
#region IsEqualTo
///
/// Determines if the Background is equal to the given one
///
/// Background to compare
/// true if equal
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool IsEqualTo(Background background)
{
return (_Color1 == background.Color1 &&
_Color2 == background.Color2 &&
(_BackColorBlend == null || _BackColorBlend.Equals(background._BackColorBlend)) &&
_GradientAngle == background.GradientAngle &&
_RadialCenter == background.RadialCenter &&
_BackFillType == background.BackFillType);
}
#endregion
#endregion
#region Internal properties
internal bool IsDisplayable
{
get
{
if (_BackFillType == BackFillType.None)
return (false);
if ((_BackColorBlend == null || _BackColorBlend.IsEmpty) &&
(_Color1.IsEmpty == true) &&
(_Color2.IsEmpty == true))
{
return (false);
}
return (true);
}
}
#endregion
#region GetBrush
///
/// GetBrush
///
///
///
public Brush GetBrush(Rectangle r)
{
if (_HatchFillType != HatchFillType.NotSet)
return (GetHatchBrush(r));
return (GetBrush(r, -1, _BackFillType));
}
public Brush GetBrush(Rectangle r, bool noAlpha)
{
return (GetBrush(r, noAlpha ? 255 : -1));
}
///
/// Get the background brush
///
/// Brush rectangle
/// 0-255 to override default
/// Brush
public Brush GetBrush(Rectangle r, int alpha)
{
return (GetBrush(r, alpha, _BackFillType));
}
///
/// Get the background brush
///
/// Brush rectangle
/// 0-255 to override default
/// BackFillType
/// Brush
public Brush GetBrush(Rectangle r, int alpha, BackFillType fillType)
{
if (_BackColorBlend != null && _BackColorBlend.IsEmpty == false)
{
if (_BackColorBlend.Colors.Length == 1)
return (new SolidBrush(GetColor(_BackColorBlend.Colors[0], alpha)));
Brush br = GetLinearBrush(r, alpha, fillType);
if (br is LinearGradientBrush)
{
ColorBlend cb = GetColorBlend(alpha);
if (cb != null)
((LinearGradientBrush)br).InterpolationColors = cb;
}
return (br);
}
if (_Color2.IsEmpty == true)
return (new SolidBrush(GetColor(_Color1, alpha)));
return (GetLinearBrush(r, alpha, fillType));
}
private Brush GetHatchBrush(Rectangle r)
{
HatchBrush brush = new HatchBrush((HatchStyle)_HatchFillType, Color1, Color2);
return (brush);
}
#region GetLinearBrush
private Brush GetLinearBrush(
Rectangle r, int alpha, BackFillType fillType)
{
LinearGradientBrush lbr = null;
if (r.Width > 0 && r.Height > 0)
{
Color color1 = GetColor(_Color1, alpha);
Color color2 = GetColor(_Color2, alpha);
switch (fillType)
{
case BackFillType.HorizontalCenter:
r.Width /= 2;
r.Width = Math.Max(1, r.Width);
lbr = new LinearGradientBrush(r, color1, color2, 0f);
break;
case BackFillType.VerticalCenter:
r.Height /= 2;
r.Height = Math.Max(1, r.Height);
lbr = new LinearGradientBrush(r, color1, color2, 90f);
break;
case BackFillType.ForwardDiagonal:
lbr = new LinearGradientBrush(r, color1, color2, LinearGradientMode.ForwardDiagonal);
break;
case BackFillType.BackwardDiagonal:
lbr = new LinearGradientBrush(r, color1, color2, LinearGradientMode.BackwardDiagonal);
break;
case BackFillType.ForwardDiagonalCenter:
r.Width /= 2;
r.Height /= 2;
lbr = new LinearGradientBrush(r, color1, color2, LinearGradientMode.ForwardDiagonal);
break;
case BackFillType.BackwardDiagonalCenter:
r.Width /= 2;
r.Height /= 2;
r.X += r.Width;
lbr = new LinearGradientBrush(r, color1, color2, LinearGradientMode.BackwardDiagonal);
break;
case BackFillType.Center:
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(r);
PathGradientBrush pbr = new PathGradientBrush(path);
pbr.CenterColor = color1;
pbr.SurroundColors = new Color[] { color2 };
ColorBlend cb = GetColorBlend(alpha);
if (cb != null)
pbr.InterpolationColors = cb;
return (pbr);
}
case BackFillType.Radial:
int n = (int) Math.Sqrt(r.Width*r.Width + r.Height*r.Height) + 4;
using (GraphicsPath path = new GraphicsPath())
{
path.AddEllipse(r.X - (n - r.Width)/2, r.Y - (n - r.Height)/2, n, n);
PathGradientBrush pbr = new PathGradientBrush(path);
pbr.CenterColor = color1;
if (_RadialCenter != .0)
pbr.CenterPoint = GetRadialCenterPoint(r, n);
pbr.SurroundColors = new Color[] { color2 };
ColorBlend cb = GetColorBlend(alpha);
if (cb != null)
pbr.InterpolationColors = cb;
return (pbr);
}
default:
lbr = new LinearGradientBrush(r, color1, color2, _GradientAngle);
break;
}
if (lbr != null)
lbr.WrapMode = WrapMode.TileFlipXY;
}
return (lbr);
}
#region GetRadialCenterPoint
private PointF GetRadialCenterPoint(Rectangle r, int n)
{
double w2 = (double)r.Width / 2;
double h2 = (double)r.Height / 2;
double z = ((double)n / 2) * _RadialCenter;
double radians = MathHelper.ToRadians(_GradientAngle);
double dx = z * Math.Cos(radians);
double dy = z * Math.Sin(radians);
PointF pf = new PointF((float)(r.X + (w2 + dx)), (float)(r.Y + (h2 + dy)));
return (pf);
}
#endregion
#endregion
#region GetColorBlend
private ColorBlend GetColorBlend(int alpha)
{
if (_BackColorBlend != null &&
_BackColorBlend.Colors != null && _BackColorBlend.Colors.Length > 0)
{
ColorBlend cb = new ColorBlend(_BackColorBlend.Colors.Length);
Color[] colors = _BackColorBlend.Colors;
if ((uint) alpha < 256)
{
for (int i = 0; i < colors.Length; i++)
colors[i] = GetColor(colors[i], alpha);
}
cb.Colors = colors;
cb.Positions = GetPositions();
return (cb);
}
return (null);
}
#endregion
#region GetPositions
private float[] GetPositions()
{
float[] cp = _BackColorBlend.Positions;
if (cp == null || cp.Length != _BackColorBlend.Colors.Length)
{
cp = new float[_BackColorBlend.Colors.Length];
float f = 1f / _BackColorBlend.Colors.Length;
for (int i = 0; i < cp.Length; i++)
cp[i] = i * f;
cp[_BackColorBlend.Colors.Length - 1] = 1;
}
return (cp);
}
#endregion
#region GetColor
private Color GetColor(Color color, int alpha)
{
if ((uint)alpha > 255)
return (color);
return (Color.FromArgb(alpha, color));
}
#endregion
#endregion
#region Copy
///
/// Creates an exact copy of the background.
///
/// Copy of the background.
public Background Copy()
{
Background style = new Background();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
///
/// Returns the copy of the style.
///
/// Copy of the style.
public void CopyTo(Background style)
{
style.Color1 = _Color1;
style.Color2 = _Color2;
style.RadialCenter = _RadialCenter;
style.GradientAngle = _GradientAngle;
style.BackFillType = _BackFillType;
style.HatchFillType = _HatchFillType;
style.BackColorBlend = (_BackColorBlend != null) ? _BackColorBlend.Copy() : null;
}
#endregion
#region GetSerialData
internal SerialElementCollection GetSerialData(string serialName)
{
SerialElementCollection sec = new SerialElementCollection();
if (serialName != null)
{
if (serialName.Equals("") == true)
serialName = "Background";
sec.AddStartElement(serialName);
}
if (_BackColorBlend != null && _BackColorBlend.IsEmpty == false)
sec.AddElement(BackColorBlend.GetSerialData());
sec.AddValue("BackFillType", BackFillType, BackFillType.Angle);
sec.AddValue("Color1", Color1, Color.Empty);
sec.AddValue("Color2", Color2, Color.Empty);
sec.AddValue("GradientAngle", GradientAngle, 90);
sec.AddValue("HatchFillType", HatchFillType, HatchFillType.NotSet);
sec.AddValue("RadialCenter", RadialCenter, 0.0d);
if (serialName != null)
sec.AddEndElement(serialName);
return (sec);
}
#endregion
#region PutSerialData
#region ProcessValue
void IProcessSerialElement.ProcessValue(SerialElement se)
{
switch (se.Name)
{
case "BackFillType":
BackFillType = (BackFillType)se.GetValueEnum(typeof(BackFillType));
break;
case "Color1":
Color1 = se.GetValueColor();
break;
case "Color2":
Color2 = se.GetValueColor();;
break;
case "GradientAngle":
GradientAngle = int.Parse(se.StringValue);
break;
case "HatchFillType":
HatchFillType = (HatchFillType)se.GetValueEnum(typeof(HatchFillType));
break;
case "RadialCenter":
RadialCenter = double.Parse(se.StringValue);
break;
default:
throw new Exception("Unknown Serial Value (" + se.Name + ")");
}
}
#endregion
#region ProcessCollection
void IProcessSerialElement.ProcessCollection(SerialElement se)
{
switch (se.Name)
{
case "BackColorBlend":
se.Sec.PutSerialData(BackColorBlend);
break;
default:
throw new Exception("Unknown Serial Collection (" + se.Name + ")");
}
}
#endregion
#endregion
#region INotifyPropertyChanged Members
///
/// Occurs when property value has changed.
///
public event PropertyChangedEventHandler PropertyChanged;
///
/// Raises the PropertyChanged event.
///
/// Event arguments
protected virtual void OnPropertyChanged(VisualPropertyChangedEventArgs e)
{
PropertyChangedEventHandler eh = PropertyChanged;
if (eh != null)
eh(this, e);
}
///
/// Raises the PropertyChanged event.
///
/// Event arguments
protected virtual void OnPropertyChangedEx(string s)
{
PropertyChangedEventHandler eh = PropertyChanged;
if (eh != null)
{
VisualPropertyChangedEventArgs e =
new VisualPropertyChangedEventArgs(s);
eh(this, e);
}
}
#endregion
#region UpdateChangeHandler
private void UpdateChangeHandler(
INotifyPropertyChanged oldValue, INotifyPropertyChanged newValue)
{
if (oldValue != null)
oldValue.PropertyChanged -= StyleChanged;
if (newValue != null)
newValue.PropertyChanged += StyleChanged;
}
#endregion
#region StyleChanged
///
/// StyleChanged
///
///
///
protected virtual void StyleChanged(
object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged((VisualPropertyChangedEventArgs)e);
}
#endregion
#region IDisposable
///
/// Dispose
///
public void Dispose()
{
BackColorBlend = null;
}
#endregion
}
#region enums
#region BackFillType
///
/// BackFillType
///
public enum BackFillType
{
///
/// No fill
///
None,
///
/// Auto
///
Auto,
///
/// Angle
///
Angle,
///
/// Center
///
Center,
///
/// HorizontalCenter
///
HorizontalCenter,
///
/// VerticalCenter
///
VerticalCenter,
///
/// ForwardDiagonal
///
ForwardDiagonal,
///
/// BackwardDiagonal
///
BackwardDiagonal,
///
/// ForwardDiagonalCenter
///
ForwardDiagonalCenter,
///
/// BackwardDiagonalCenter
///
BackwardDiagonalCenter,
///
/// Radial
///
Radial,
}
#endregion
#region HatchFillType
public enum HatchFillType
{
NotSet = -1,
///
/// A pattern of horizontal lines.
///
Horizontal = HatchStyle.Horizontal,
///
/// A pattern of vertical lines.
///
Vertical = HatchStyle.Vertical,
///
/// A pattern of lines on a diagonal from upper left to lower right..
///
ForwardDiagonal = HatchStyle.ForwardDiagonal,
///
/// A pattern of lines on a diagonal from upper right to lower left.
///
BackwardDiagonal = HatchStyle.BackwardDiagonal,
///
/// Specifies horizontal and vertical lines that cross.
///
Cross = HatchStyle.Cross,
///
/// A pattern of crisscross diagonal lines.
///
DiagonalCross = HatchStyle.DiagonalCross,
///
/// Specifies a 5-percent hatch. The ratio of foreground color to background
/// color is 5:100.
///
Percent05 = HatchStyle.Percent05,
///
/// Specifies a 10-percent hatch. The ratio of foreground color to background
/// color is 10:100.
///
Percent10 = HatchStyle.Percent10,
///
/// Specifies a 20-percent hatch. The ratio of foreground color to background
/// color is 20:100.
///
Percent20 = HatchStyle.Percent20,
///
/// Specifies a 25-percent hatch. The ratio of foreground color to background
/// color is 25:100.
///
Percent25 = HatchStyle.Percent25,
///
/// Specifies a 30-percent hatch. The ratio of foreground color to background
/// color is 30:100.
///
Percent30 = HatchStyle.Percent30,
///
/// Specifies a 40-percent hatch. The ratio of foreground color to background
/// color is 40:100.
/// /
Percent40 = HatchStyle.Percent40,
///
/// Specifies a 50-percent hatch. The ratio of foreground color to background
/// color is 50:100.
///
Percent50 = HatchStyle.Percent50,
///
/// Specifies a 60-percent hatch. The ratio of foreground color to background
/// color is 60:100.
///
Percent60 = HatchStyle.Percent60,
///
/// Specifies a 70-percent hatch. The ratio of foreground color to background
/// color is 70:100.
/// /
Percent70 = HatchStyle.Percent70,
///
/// Specifies a 75-percent hatch. The ratio of foreground color to background
/// color is 75:100.
///
Percent75 = HatchStyle.Percent75,
///
/// Specifies a 80-percent hatch. The ratio of foreground color to background
/// color is 80:100.
///
Percent80 = HatchStyle.Percent80,
///
/// Specifies a 90-percent hatch. The ratio of foreground color to background
/// color is 90:100.
///
Percent90 = HatchStyle.Percent90,
///
/// Specifies diagonal lines that slant to the right from top points to bottom
/// points and are spaced 50 percent closer together than System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal,
/// but are not antialiased.
///
LightDownwardDiagonal = HatchStyle.LightDownwardDiagonal,
///
/// Specifies diagonal lines that slant to the left from top points to bottom
/// points and are spaced 50 percent closer together than System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal,
/// but they are not antialiased.
///
LightUpwardDiagonal = HatchStyle.LightUpwardDiagonal,
///
/// Specifies diagonal lines that slant to the right from top points to bottom
/// points, are spaced 50 percent closer together than, and are twice the width
/// of System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal. This hatch pattern
/// is not antialiased.
///
DarkDownwardDiagonal = HatchStyle.DarkDownwardDiagonal,
///
/// Specifies diagonal lines that slant to the left from top points to bottom
/// points, are spaced 50 percent closer together than System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal,
/// and are twice its width, but the lines are not antialiased.
///
DarkUpwardDiagonal = HatchStyle.DarkUpwardDiagonal,
///
/// Specifies diagonal lines that slant to the right from top points to bottom
/// points, have the same spacing as hatch style System.Drawing.Drawing2D.HatchStyle.ForwardDiagonal,
/// and are triple its width, but are not antialiased.
///
WideDownwardDiagonal = HatchStyle.WideDownwardDiagonal,
///
/// Specifies diagonal lines that slant to the left from top points to bottom
/// points, have the same spacing as hatch style System.Drawing.Drawing2D.HatchStyle.BackwardDiagonal,
/// and are triple its width, but are not antialiased.
///
WideUpwardDiagonal = HatchStyle.WideUpwardDiagonal,
///
/// Specifies vertical lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Vertical.
///
LightVertical = HatchStyle.LightVertical,
///
/// Specifies horizontal lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Horizontal.
///
LightHorizontal = HatchStyle.LightHorizontal,
///
/// Specifies vertical lines that are spaced 75 percent closer together than
/// hatch style System.Drawing.Drawing2D.HatchStyle.Vertical (or 25 percent closer
/// together than System.Drawing.Drawing2D.HatchStyle.LightVertical).
///
NarrowVertical = HatchStyle.NarrowVertical,
///
/// Specifies horizontal lines that are spaced 75 percent closer together than
/// hatch style System.Drawing.Drawing2D.HatchStyle.Horizontal (or 25 percent
/// closer together than System.Drawing.Drawing2D.HatchStyle.LightHorizontal).
///
NarrowHorizontal = HatchStyle.NarrowHorizontal,
///
/// Specifies vertical lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Vertical and are twice its width.
///
DarkVertical = HatchStyle.DarkVertical,
///
/// Specifies horizontal lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Horizontal and are twice the width of
/// System.Drawing.Drawing2D.HatchStyle.Horizontal.
///
DarkHorizontal = HatchStyle.DarkHorizontal,
///
/// Specifies dashed diagonal lines, that slant to the right from top points
/// to bottom points.
///
DashedDownwardDiagonal = HatchStyle.DashedDownwardDiagonal,
///
/// Specifies dashed diagonal lines, that slant to the left from top points to
/// bottom points.
///
DashedUpwardDiagonal = HatchStyle.DashedUpwardDiagonal,
///
/// Specifies dashed horizontal lines.
///
DashedHorizontal = HatchStyle.DashedHorizontal,
///
/// Specifies dashed vertical lines.
///
DashedVertical = HatchStyle.DashedVertical,
///
/// Specifies a hatch that has the appearance of confetti.
///
SmallConfetti = HatchStyle.SmallConfetti,
///
/// Specifies a hatch that has the appearance of confetti, and is composed of
/// larger pieces than System.Drawing.Drawing2D.HatchStyle.SmallConfetti.
///
LargeConfetti = HatchStyle.LargeConfetti,
///
/// Specifies horizontal lines that are composed of zigzags.
///
ZigZag = HatchStyle.ZigZag,
///
/// Specifies horizontal lines that are composed of tildes.
///
Wave = HatchStyle.Wave,
///
/// Specifies a hatch that has the appearance of layered bricks that slant to
/// the left from top points to bottom points.
///
DiagonalBrick = HatchStyle.DiagonalBrick,
///
/// Specifies a hatch that has the appearance of horizontally layered bricks.
///
HorizontalBrick = HatchStyle.HorizontalBrick,
///
/// Specifies a hatch that has the appearance of a woven material.
///
Weave = HatchStyle.Weave,
///
/// Specifies a hatch that has the appearance of a plaid material.
///
Plaid = HatchStyle.Plaid,
///
/// Specifies a hatch that has the appearance of divots.
///
Divot = HatchStyle.Divot,
///
/// Specifies horizontal and vertical lines, each of which is composed of dots,
/// that cross.
///
DottedGrid = HatchStyle.DottedGrid,
///
/// Specifies forward diagonal and backward diagonal lines, each of which is
/// composed of dots, that cross.
///
DottedDiamond = HatchStyle.DottedDiamond,
///
/// Specifies a hatch that has the appearance of diagonally layered shingles
/// that slant to the right from top points to bottom points.
///
Shingle = HatchStyle.Shingle,
///
/// Specifies a hatch that has the appearance of a trellis.
///
Trellis = HatchStyle.Trellis,
///
/// Specifies a hatch that has the appearance of spheres laid adjacent to one
/// another.
///
Sphere = HatchStyle.Sphere,
///
/// Specifies horizontal and vertical lines that cross and are spaced 50 percent
/// closer together than hatch style System.Drawing.Drawing2D.HatchStyle.Cross.
///
SmallGrid = HatchStyle.SmallGrid,
///
/// Specifies a hatch that has the appearance of a checkerboard.
///
SmallCheckerBoard = HatchStyle.SmallCheckerBoard,
///
/// Specifies a hatch that has the appearance of a checkerboard with squares
/// that are twice the size of System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard.
///
LargeCheckerBoard = HatchStyle.LargeCheckerBoard,
///
/// Specifies forward diagonal and backward diagonal lines that cross but are
/// not antialiased.
///
OutlinedDiamond = HatchStyle.OutlinedDiamond,
///
/// Specifies a hatch that has the appearance of a checkerboard placed diagonally.
///
SolidDiamond = HatchStyle.SolidDiamond,
}
#endregion
#endregion
#region BackgroundConvertor
///
/// BackgroundConvertor
///
public class BackgroundConvertor : ExpandableObjectConverter
{
///
/// ConvertTo
///
///
///
///
///
///
public override object ConvertTo(
ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
Background gc = value as Background;
if (gc != null)
{
if (gc.BackColorBlend != null && gc.BackColorBlend.IsEmpty == false)
return ("Blended");
ColorConverter cvt = new ColorConverter();
string s = gc.Color1.IsEmpty ? " " : cvt.ConvertToString(gc.Color1);
if (gc.Color2 != Color.Empty)
s += ", " + cvt.ConvertToString(gc.Color2);
return (s);
}
}
return (base.ConvertTo(context, culture, value, destinationType));
}
}
#endregion
#region BackgroundEditor
///
/// BackgroundEditor
///
public class BackgroundEditor : UITypeEditor
{
#region GetPaintValueSupported
///
/// GetPaintValueSupported
///
///
///
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (true);
}
#endregion
#region PaintValue
///
/// PaintValue
///
///
public override void PaintValue(PaintValueEventArgs e)
{
Background b = e.Value as Background;
if (b != null)
{
using (Brush br = b.GetBrush(e.Bounds))
e.Graphics.FillRectangle(br, e.Bounds);
}
}
#endregion
}
#endregion
}