270 lines
6.7 KiB
C#

using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar.Charts.Style
{
/// <summary>
/// Represents the visual style of an element.
/// </summary>
[TypeConverter(typeof(VisualStylesConverter))]
public class CrosshairValueVisualStyle : VisualStyle
{
#region Private variables
private string _TextFormat;
private DropShadowVisualStyle _DropShadow;
#endregion
#region Public properties
#region DropShadow
/// <summary>
/// Gets or sets the visual style for the DropShadow.
/// </summary>
[Category("Style")]
[Description("Indicates the visual style for the DropShadow.")]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public DropShadowVisualStyle DropShadow
{
get
{
if (_DropShadow == null)
{
_DropShadow = new DropShadowVisualStyle();
UpdateChangeHandler(null, _DropShadow);
}
return (_DropShadow);
}
set
{
if (_DropShadow != value)
{
DropShadowVisualStyle oldValue = _DropShadow;
_DropShadow = value;
OnStyleChanged("DropShadow", oldValue, value);
if (oldValue != null)
oldValue.Dispose();
}
}
}
#endregion
#region TextFormat
/// <summary>
/// Gets or sets the Text Format specifier
/// </summary>
[DefaultValue(null)]
[Description("Indicates the Text Format specifier")]
public string TextFormat
{
get { return (_TextFormat); }
set
{
if (_TextFormat != value)
{
_TextFormat = value;
OnPropertyChangedEx("TextFormat", VisualChangeType.Render);
}
}
}
#endregion
#region IsEmpty
/// <summary>
/// Gets whether the style is logically Empty.
/// </summary>
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[Description("Gets whether the style is logically Empty.")]
public override bool IsEmpty
{
get
{
return ((_DropShadow == null || _DropShadow.IsEmpty) &&
(string.IsNullOrEmpty(_TextFormat) == true) &&
(base.IsEmpty == true));
}
}
#endregion
#endregion
#region ApplyStyle
/// <summary>
/// Applies the style to instance of this style.
/// </summary>
/// <param name="style">Style to apply.</param>
public void ApplyStyle(CrosshairValueVisualStyle style)
{
if (style != null)
{
base.ApplyStyle(style);
if (style._DropShadow != null && style.DropShadow.IsEmpty == false)
DropShadow.ApplyStyle(style.DropShadow);
if (string.IsNullOrEmpty(style.TextFormat) == false)
_TextFormat = style.TextFormat;
}
}
#endregion
#region ApplyDefaults
public override void ApplyDefaults()
{
if (Background.IsEmpty == true)
Background = new Background(ControlPaint.LightLight(Color.Fuchsia));
if (BorderColor.IsEmpty == true)
BorderColor = new BorderColor(Color.Black);
if (BorderPattern.IsEmpty == true)
BorderPattern = new BorderPattern(LinePattern.Solid);
if (BorderThickness.IsEmpty == true)
BorderThickness = new Thickness(1);
base.ApplyDefaults();
}
#endregion
#region Copy
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public new CrosshairValueVisualStyle Copy()
{
CrosshairValueVisualStyle style = new CrosshairValueVisualStyle();
CopyTo(style);
return (style);
}
#endregion
#region CopyTo
/// <summary>
/// Returns the copy of the style.
/// </summary>
/// <returns>Copy of the style.</returns>
public void CopyTo(CrosshairValueVisualStyle style)
{
base.CopyTo(style);
style.DropShadow = (_DropShadow != null) ? DropShadow.Copy() : null;
style.TextFormat = _TextFormat;
}
#endregion
#region GetSerialData
internal override SerialElementCollection GetSerialData(string serialName)
{
SerialElementCollection sec = new SerialElementCollection();
if (serialName != null)
{
if (serialName.Equals("") == true)
serialName = "CrosshairValueVisualStyle";
sec.AddStartElement(serialName);
}
if (_DropShadow != null && _DropShadow.IsEmpty == false)
sec.AddElement(_DropShadow.GetSerialData("DropShadow"));
sec.AddValue("TextFormat", TextFormat, null);
sec.AddElement(base.GetSerialData(null));
if (serialName != null)
sec.AddEndElement(serialName);
return (sec);
}
#endregion
#region PutSerialData
#region ProcessValue
internal override void ProcessValue(SerialElement se)
{
switch (se.Name)
{
case "TextFormat":
TextFormat = se.StringValue;
break;
default:
base.ProcessValue(se);
break;
}
}
#endregion
#region ProcessCollection
internal override void ProcessCollection(SerialElement se)
{
SerialElementCollection sec = se.Sec;
switch (se.Name)
{
case "DropShadow":
sec.PutSerialData(DropShadow);
break;
default:
base.ProcessCollection(se);
break;
}
}
#endregion
#endregion
#region IDisposable
/// <summary>
/// Dispose
/// </summary>
public override void Dispose()
{
DropShadow = null;
base.Dispose();
}
#endregion
}
}