1400 lines
41 KiB
C#

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
{
/// <summary>
/// Represents background of visual style.
/// </summary>
[TypeConverter(typeof(BackgroundConvertor))]
[Editor(typeof(BackgroundEditor), typeof(UITypeEditor))]
public class Background : INotifyPropertyChanged, IDisposable, IProcessSerialElement
{
#region Static data
///<summary>
/// Empty
///</summary>
/// <summary>
/// Returns Empty instance of Background.
/// </summary>
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
/// <summary>
/// Creates new instance of the object.
/// </summary>
public Background() { }
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start color.</param>
public Background(Color color1)
{
_Color1 = color1;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start color.</param>
/// <param name="color2">End color.</param>
public Background(Color color1, Color color2)
{
_Color1 = color1;
_Color2 = color2;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start color in hexadecimal representation like FFFFFF.</param>
/// <param name="color2">End color in hexadecimal representation like FFFFFF.</param>
public Background(string color1, string color2)
{
_Color1 = ColorFactory.GetColor(color1);
_Color2 = ColorFactory.GetColor(color2);
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start color in 32-bit RGB representation.</param>
/// <param name="color2">End color in 32-bit RGB representation.</param>
public Background(int color1, int color2)
{
_Color1 = ColorFactory.GetColor(color1);
_Color2 = ColorFactory.GetColor(color2);
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start 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 Background(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">Start color.</param>
/// <param name="color2">End color.</param>
/// <param name="gradientAngle">Gradient angle.</param>
public Background(Color color1, Color color2, int gradientAngle)
{
_Color1 = color1;
_Color2 = color2;
GradientAngle = gradientAngle;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="color1">Start color.</param>
/// <param name="color2">End color.</param>
/// <param name="fillType">Gradient angle.</param>
public Background(Color color1, Color color2, BackFillType fillType)
{
_Color1 = color1;
_Color2 = color2;
_BackFillType = fillType;
}
#endregion
#region Public properties
#region BackColorBlend
/// <summary>
/// Gets or sets the BackColorBlend.
/// </summary>
[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
/// <summary>
/// Gets or sets the Gradient BackFillType
/// </summary>
[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
/// <summary>
/// Gets or sets the start color.
/// </summary>
[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
/// <summary>
/// Gets or sets the Ending Gradient Color
/// </summary>
[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
/// <summary>
/// Gets or sets the gradient angle (default is 90)
/// </summary>
[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
/// <summary>
/// Gets or sets the Gradient BackFillType
/// </summary>
[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
/// <summary>
/// Gets or sets the Radial Gradient Center expressed as a percentage of the radius (from 0 to 1)
/// </summary>
[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
/// <summary>
/// Gets whether the backcolor brush is a SolidBrush
/// </summary>
[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
/// <summary>
/// Gets whether Background is empty.
/// </summary>
[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
/// <summary>
/// Determines if the Background is equal to the given one
/// </summary>
/// <param name="background">Background to compare</param>
/// <returns>true if equal</returns>
[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
///<summary>
/// GetBrush
///</summary>
///<param name="r"></param>
///<returns></returns>
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));
}
/// <summary>
/// Get the background brush
/// </summary>
/// <param name="r">Brush rectangle</param>
/// <param name="alph">0-255 to override default</param>
/// <returns>Brush</returns>
public Brush GetBrush(Rectangle r, int alpha)
{
return (GetBrush(r, alpha, _BackFillType));
}
/// <summary>
/// Get the background brush
/// </summary>
/// <param name="r">Brush rectangle</param>
/// <param name="alph">0-255 to override default</param>
/// <param name="fillType">BackFillType</param>
/// <returns>Brush</returns>
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
/// <summary>
/// Creates an exact copy of the background.
/// </summary>
/// <returns>Copy of the background.</returns>
public Background Copy()
{
Background style = new Background();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
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
/// <summary>
/// Occurs when property value has changed.
/// </summary>
public event PropertyChangedEventHandler PropertyChanged;
/// <summary>
/// Raises the PropertyChanged event.
/// </summary>
/// <param name="e">Event arguments</param>
protected virtual void OnPropertyChanged(VisualPropertyChangedEventArgs e)
{
PropertyChangedEventHandler eh = PropertyChanged;
if (eh != null)
eh(this, e);
}
/// <summary>
/// Raises the PropertyChanged event.
/// </summary>
/// <param name="s">Event arguments</param>
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
/// <summary>
/// StyleChanged
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected virtual void StyleChanged(
object sender, PropertyChangedEventArgs e)
{
OnPropertyChanged((VisualPropertyChangedEventArgs)e);
}
#endregion
#region IDisposable
/// <summary>
/// Dispose
/// </summary>
public void Dispose()
{
BackColorBlend = null;
}
#endregion
}
#region enums
#region BackFillType
///<summary>
/// BackFillType
///</summary>
public enum BackFillType
{
/// <summary>
/// No fill
/// </summary>
None,
/// <summary>
/// Auto
/// </summary>
Auto,
///<summary>
/// Angle
///</summary>
Angle,
///<summary>
/// Center
///</summary>
Center,
///<summary>
/// HorizontalCenter
///</summary>
HorizontalCenter,
///<summary>
/// VerticalCenter
///</summary>
VerticalCenter,
///<summary>
/// ForwardDiagonal
///</summary>
ForwardDiagonal,
///<summary>
/// BackwardDiagonal
///</summary>
BackwardDiagonal,
///<summary>
/// ForwardDiagonalCenter
///</summary>
ForwardDiagonalCenter,
///<summary>
/// BackwardDiagonalCenter
///</summary>
BackwardDiagonalCenter,
///<summary>
/// Radial
///</summary>
Radial,
}
#endregion
#region HatchFillType
public enum HatchFillType
{
NotSet = -1,
/// <summary>
/// A pattern of horizontal lines.
/// </summary>
Horizontal = HatchStyle.Horizontal,
/// <summary>
/// A pattern of vertical lines.
/// </summary>
Vertical = HatchStyle.Vertical,
/// <summary>
/// A pattern of lines on a diagonal from upper left to lower right..
/// </summary>
ForwardDiagonal = HatchStyle.ForwardDiagonal,
/// <summary>
/// A pattern of lines on a diagonal from upper right to lower left.
/// </summary>
BackwardDiagonal = HatchStyle.BackwardDiagonal,
/// <summary>
/// Specifies horizontal and vertical lines that cross.
/// </summary>
Cross = HatchStyle.Cross,
/// <summary>
/// A pattern of crisscross diagonal lines.
/// </summary>
DiagonalCross = HatchStyle.DiagonalCross,
/// <summary>
/// Specifies a 5-percent hatch. The ratio of foreground color to background
/// color is 5:100.
/// </summary>
Percent05 = HatchStyle.Percent05,
/// <summary>
/// Specifies a 10-percent hatch. The ratio of foreground color to background
/// color is 10:100.
/// </summary>
Percent10 = HatchStyle.Percent10,
/// <summary>
/// Specifies a 20-percent hatch. The ratio of foreground color to background
/// color is 20:100.
/// </summary>
Percent20 = HatchStyle.Percent20,
/// <summary>
/// Specifies a 25-percent hatch. The ratio of foreground color to background
/// color is 25:100.
/// </summary>
Percent25 = HatchStyle.Percent25,
/// <summary>
/// Specifies a 30-percent hatch. The ratio of foreground color to background
/// color is 30:100.
/// </summary>
Percent30 = HatchStyle.Percent30,
/// <summary>
/// Specifies a 40-percent hatch. The ratio of foreground color to background
/// color is 40:100.
/// /<summary>
Percent40 = HatchStyle.Percent40,
/// <summary>
/// Specifies a 50-percent hatch. The ratio of foreground color to background
/// color is 50:100.
/// </summary>
Percent50 = HatchStyle.Percent50,
/// <summary>
/// Specifies a 60-percent hatch. The ratio of foreground color to background
/// color is 60:100.
/// </summary>
Percent60 = HatchStyle.Percent60,
/// <summary>
/// Specifies a 70-percent hatch. The ratio of foreground color to background
/// color is 70:100.
/// /<summary>
Percent70 = HatchStyle.Percent70,
/// <summary>
/// Specifies a 75-percent hatch. The ratio of foreground color to background
/// color is 75:100.
/// </summary>
Percent75 = HatchStyle.Percent75,
/// <summary>
/// Specifies a 80-percent hatch. The ratio of foreground color to background
/// color is 80:100.
/// </summary>
Percent80 = HatchStyle.Percent80,
/// <summary>
/// Specifies a 90-percent hatch. The ratio of foreground color to background
/// color is 90:100.
/// </summary>
Percent90 = HatchStyle.Percent90,
/// <summary>
/// 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.
/// </summary>
LightDownwardDiagonal = HatchStyle.LightDownwardDiagonal,
/// <summary>
/// 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.
/// </summary>
LightUpwardDiagonal = HatchStyle.LightUpwardDiagonal,
/// <summary>
/// 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.
/// </summary>
DarkDownwardDiagonal = HatchStyle.DarkDownwardDiagonal,
/// <summary>
/// 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.
/// </summary>
DarkUpwardDiagonal = HatchStyle.DarkUpwardDiagonal,
/// <summary>
/// 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.
/// </summary>
WideDownwardDiagonal = HatchStyle.WideDownwardDiagonal,
/// <summary>
/// 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.
/// </summary>
WideUpwardDiagonal = HatchStyle.WideUpwardDiagonal,
/// <summary>
/// Specifies vertical lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Vertical.
/// </summary>
LightVertical = HatchStyle.LightVertical,
/// <summary>
/// Specifies horizontal lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Horizontal.
/// </summary>
LightHorizontal = HatchStyle.LightHorizontal,
/// <summary>
/// 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).
/// </summary>
NarrowVertical = HatchStyle.NarrowVertical,
/// <summary>
/// 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).
/// </summary>
NarrowHorizontal = HatchStyle.NarrowHorizontal,
/// <summary>
/// Specifies vertical lines that are spaced 50 percent closer together than
/// System.Drawing.Drawing2D.HatchStyle.Vertical and are twice its width.
/// </summary>
DarkVertical = HatchStyle.DarkVertical,
/// <summary>
/// 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.
/// </summary>
DarkHorizontal = HatchStyle.DarkHorizontal,
/// <summary>
/// Specifies dashed diagonal lines, that slant to the right from top points
/// to bottom points.
/// </summary>
DashedDownwardDiagonal = HatchStyle.DashedDownwardDiagonal,
/// <summary>
/// Specifies dashed diagonal lines, that slant to the left from top points to
/// bottom points.
/// </summary>
DashedUpwardDiagonal = HatchStyle.DashedUpwardDiagonal,
/// <summary>
/// Specifies dashed horizontal lines.
/// </summary>
DashedHorizontal = HatchStyle.DashedHorizontal,
/// <summary>
/// Specifies dashed vertical lines.
/// </summary>
DashedVertical = HatchStyle.DashedVertical,
/// <summary>
/// Specifies a hatch that has the appearance of confetti.
/// </summary>
SmallConfetti = HatchStyle.SmallConfetti,
/// <summary>
/// Specifies a hatch that has the appearance of confetti, and is composed of
/// larger pieces than System.Drawing.Drawing2D.HatchStyle.SmallConfetti.
/// </summary>
LargeConfetti = HatchStyle.LargeConfetti,
/// <summary>
/// Specifies horizontal lines that are composed of zigzags.
/// </summary>
ZigZag = HatchStyle.ZigZag,
/// <summary>
/// Specifies horizontal lines that are composed of tildes.
/// </summary>
Wave = HatchStyle.Wave,
/// <summary>
/// Specifies a hatch that has the appearance of layered bricks that slant to
/// the left from top points to bottom points.
/// </summary>
DiagonalBrick = HatchStyle.DiagonalBrick,
/// <summary>
/// Specifies a hatch that has the appearance of horizontally layered bricks.
/// </summary>
HorizontalBrick = HatchStyle.HorizontalBrick,
/// <summary>
/// Specifies a hatch that has the appearance of a woven material.
/// </summary>
Weave = HatchStyle.Weave,
/// <summary>
/// Specifies a hatch that has the appearance of a plaid material.
/// </summary>
Plaid = HatchStyle.Plaid,
/// <summary>
/// Specifies a hatch that has the appearance of divots.
/// </summary>
Divot = HatchStyle.Divot,
/// <summary>
/// Specifies horizontal and vertical lines, each of which is composed of dots,
/// that cross.
/// </summary>
DottedGrid = HatchStyle.DottedGrid,
/// <summary>
/// Specifies forward diagonal and backward diagonal lines, each of which is
/// composed of dots, that cross.
/// </summary>
DottedDiamond = HatchStyle.DottedDiamond,
/// <summary>
/// Specifies a hatch that has the appearance of diagonally layered shingles
/// that slant to the right from top points to bottom points.
/// </summary>
Shingle = HatchStyle.Shingle,
/// <summary>
/// Specifies a hatch that has the appearance of a trellis.
/// </summary>
Trellis = HatchStyle.Trellis,
/// <summary>
/// Specifies a hatch that has the appearance of spheres laid adjacent to one
/// another.
/// </summary>
Sphere = HatchStyle.Sphere,
/// <summary>
/// Specifies horizontal and vertical lines that cross and are spaced 50 percent
/// closer together than hatch style System.Drawing.Drawing2D.HatchStyle.Cross.
/// </summary>
SmallGrid = HatchStyle.SmallGrid,
/// <summary>
/// Specifies a hatch that has the appearance of a checkerboard.
/// </summary>
SmallCheckerBoard = HatchStyle.SmallCheckerBoard,
/// <summary>
/// Specifies a hatch that has the appearance of a checkerboard with squares
/// that are twice the size of System.Drawing.Drawing2D.HatchStyle.SmallCheckerBoard.
/// </summary>
LargeCheckerBoard = HatchStyle.LargeCheckerBoard,
/// <summary>
/// Specifies forward diagonal and backward diagonal lines that cross but are
/// not antialiased.
/// </summary>
OutlinedDiamond = HatchStyle.OutlinedDiamond,
/// <summary>
/// Specifies a hatch that has the appearance of a checkerboard placed diagonally.
/// </summary>
SolidDiamond = HatchStyle.SolidDiamond,
}
#endregion
#endregion
#region BackgroundConvertor
///<summary>
/// BackgroundConvertor
///</summary>
public class BackgroundConvertor : ExpandableObjectConverter
{
/// <summary>
/// ConvertTo
/// </summary>
/// <param name="context"></param>
/// <param name="culture"></param>
/// <param name="value"></param>
/// <param name="destinationType"></param>
/// <returns></returns>
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
///<summary>
/// BackgroundEditor
///</summary>
public class BackgroundEditor : UITypeEditor
{
#region GetPaintValueSupported
/// <summary>
/// GetPaintValueSupported
/// </summary>
/// <param name="context"></param>
/// <returns></returns>
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return (true);
}
#endregion
#region PaintValue
/// <summary>
/// PaintValue
/// </summary>
/// <param name="e"></param>
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
}