
Signature
http://www.sturmnet.org/blog
Ok, so sorry for those who dislike this...here is the code.
My custom control code :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace MyComponent
{
public partial class Frame : UserControl
{
public Frame()
{
InitializeComponent();
//this.m_GridLines = new CGridLine();
}
private CGridLine m_GridLines= new CGridLine();
[Category("Appearance")]
[Browsable(true)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Description("Setup Style, Type and Color of gridlines to draw.")]
[TypeConverter(typeof(CGridLineConverter))]
public CGridLine GridLines
{
get
{
return this.m_GridLines;
}
set
{
this.m_GridLines = value;
}
}
}
}
my GridLines class and its converter code :
using System;
using System.Drawing;
using System.ComponentModel;
using System.Globalization;
using System.Diagnostics;
namespace MyComponent
{
/// <summary>
/// Specifies how a Table draws grid lines between its rows and columns
/// </summary>
public enum GridLines
{
/// <summary>
/// No grid lines are drawn
/// </summary>
None = 0,
/// <summary>
/// Grid lines are only drawn between columns
/// </summary>
Columns = 1,
/// <summary>
/// Grid lines are only drawn between rows
/// </summary>
Rows = 2,
/// <summary>
/// Grid lines are drawn between rows and columns
/// </summary>
All = 3
}
/// <summary>
/// Specifies the style of the lines drawn when a Table draws its
grid lines
/// </summary>
public enum GridLineStyle
{
/// <summary>
/// Specifies a solid line
/// </summary>
Solid = 0,
/// <summary>
/// Specifies a line consisting of dashes
/// </summary>
Dash = 1,
/// <summary>
/// Specifies a line consisting of dots
/// </summary>
Dot = 2,
/// <summary>
/// Specifies a line consisting of a repeating pattern of dash-dot
/// </summary>
DashDot = 3,
/// <summary>
/// Specifies a line consisting of a repeating pattern of dash-dot-dot
/// </summary>
DashDotDot = 4
}
[TypeConverter(typeof(CGridLineConverter))]
public class CGridLine
{
#region Class Data
private GridLines m_GridLines;
private GridLineStyle m_GridLinesStyle;
private Color m_GridLinesColor;
#endregion
#region Constructor
public CGridLine()
{
this.m_GridLines = GridLines.None;
this.m_GridLinesColor = System.Drawing.SystemColors.ActiveBorder;
this.m_GridLinesStyle = GridLineStyle.Solid;
}
public CGridLine(GridLines LineType, GridLineStyle LineStyle, Color
LineColor)
{
this.m_GridLines = LineType;
this.m_GridLinesColor = LineColor;
this.m_GridLinesStyle = LineStyle;
}
#endregion
#region Properties
/// <summary>
/// Style of the GridLines
/// </summary>
///
[RefreshProperties(RefreshProperties.Repaint)]
[NotifyParentProperty(true)]
[DefaultValue(typeof(GridLineStyle), "Solid")]
public GridLineStyle Style
{
get
{
return this.m_GridLinesStyle;
}
set
{
this.m_GridLinesStyle = value;
}
}
/// <summary>
/// Types of GridLines
/// </summary>
[RefreshProperties(RefreshProperties.Repaint)]
[NotifyParentProperty(true)]
[DefaultValue(typeof(GridLines), "None")]
public GridLines Lines
{
get
{
return this.m_GridLines;
}
set
{
this.m_GridLines = value;
}
}
/// <summary>
/// Color of the GridLine
/// </summary>
[RefreshProperties(RefreshProperties.Repaint)]
[NotifyParentProperty(true)]
[DefaultValue(typeof(Color), "ActiveBorder")]
public Color Color
{
get
{
return this.m_GridLinesColor;
}
set
{
this.m_GridLinesColor = value;
}
}
#endregion
}
public class CGridLineConverter : ExpandableObjectConverter
{
/// <summary>
/// Check if it the parameter (context) is a string and can convert
it to class type (destinationType)
/// </summary>
/// <param name="context">string that holds the class type
information</param>
/// <param name="destinationType">class type to which the context
must be converted</param>
/// <returns>true if it's possible, or false in case of impossible
conversion</returns>
public override bool CanConvertTo(ITypeDescriptorContext
context,Type destinationType)
{
if (destinationType == typeof(string))
{
return true;
}
else
{
return base.CanConvertTo(context, destinationType);
}
}
/// <summary>
///
/// </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))
{
return ToString(value);
}
else
{
return base.ConvertTo(context, culture, value, destinationType);
}
}
/// <summary>
/// ConverToString whole subproperties
/// </summary>
/// <param name="value">value holds by CGridLine property</param>
/// <returns>Formatted string that holds the CGridLine property
converted into text</returns>
private string ToString(object value)
{
CGridLine m_GridLine = (CGridLine)value;
ColorConverter ColConverter = new ColorConverter();
StringConverter StrConverter = new StringConverter();
return String.Format("{0}, {1}, {2}",
m_GridLine.Lines.ToString(),
m_GridLine.Style.ToString(),
ColConverter.ConvertToString(m_GridLine.Color));
}
public override bool CanConvertFrom(ITypeDescriptorContext
context,Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
else
{
return base.CanConvertFrom(context, sourceType);
}
}
public override object ConvertFrom(ITypeDescriptorContext context,
CultureInfo culture, object value)
{
if (value is string)
{
return FromString(value);
}
else
{
return base.ConvertFrom(context, culture, value);
}
}
private CGridLine FromString(object value)
{
string[] values = ((string)value).Split(',');
if (values.Length != 3)
throw new ArgumentException("Could not convert the value !");
try
{
CGridLine my_GridLine = new CGridLine();
ColorConverter ColConverter = new ColorConverter();
StringConverter StrConverter = new StringConverter();
my_GridLine.Lines = (GridLines)Enum.Parse(typeof(GridLines),
values[0], true);
my_GridLine.Style =
(GridLineStyle)Enum.Parse(typeof(GridLineStyle), values[1], true);
my_GridLine.Color =
(Color)ColConverter.ConvertFromString(values[2]);
return my_GridLine;
}
catch (Exception err)
{
String ErrorMsg = "Could not convert the value \n\n Error
Message : " + err.Message;
throw new ArgumentException(ErrorMsg);
}
}
}
}
You can cut and paste into a brand new usercontrol and check what is the
behavior based on my previous post regarding test process.
Alain.
> Hello Al,
>
[quoted text clipped - 4 lines]
>
> Oliver Sturm