SpreadRow.cs スプレッドシート行属性クラスです。
using System;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
namespace SpreadControl
{
/// <summary>
/// SpreadRow の概要の説明です。
/// </summary>
[Serializable]
[TypeConverter(typeof(SpreadRowConverter))]
public class SpreadRow
{
#region ローカル変数
private string _headerText ;
private Font _headerFont ;
private Color _headerForecolor ;
private Color _headerBackcolor ;
#endregion
#region クラスの生成・消滅
public SpreadRow()
{
_headerText = "" ;
_headerFont = TextBox.DefaultFont ;
_headerForecolor = TextBox.DefaultForeColor ;
_headerBackcolor = TextBox.DefaultBackColor ;
}
public SpreadRow( string headerText, Font headerFont, Color headerForecolor, Color headerBackcolor )
{
_headerText = headerText ;
_headerFont = headerFont ;
_headerForecolor = headerForecolor ;
_headerBackcolor = headerBackcolor ;
}
#endregion
#region 公開プロパティ
[Description("ヘッダーテキストの表示です。"),Category("表示")]
public string HeaderText
{
get
{
return _headerText ;
}
set
{
_headerText = value ;
RaisePropertyChange() ;
}
}
[Description("ヘッダーでテキストを表示するフォントです。"),Category("表示")]
public Font HeaderFont
{
get
{
return _headerFont ;
}
set
{
_headerFont = value ;
RaisePropertyChange() ;
}
}
[Description("ヘッダーでテキストを表示するために使用する前景色です。"),Category("表示")]
public Color HeaderForeColor
{
get
{
return _headerForecolor ;
}
set
{
_headerForecolor = value ;
RaisePropertyChange() ;
}
}
[Description("ヘッダーでテキストを表示するために使用する背景色です。"),Category("表示")]
public Color HeaderBackColor
{
get
{
return _headerBackcolor ;
}
set
{
_headerBackcolor = value ;
RaisePropertyChange() ;
}
}
#endregion
#region 公開イベント
private EventHandler onPropertyChange ;
[Description("プロパティ変更されたときに発生します。"),Category("アクション")]
public event EventHandler PropertyChange
{ add { onPropertyChange += value; } remove { onPropertyChange -= value; } }
protected virtual void OnPropertyChange(EventArgs e)
{
if (onPropertyChange != null) onPropertyChange(this, e);
}
private void RaisePropertyChange()
{
EventArgs e = new EventArgs() ;
OnPropertyChange( e ) ;
}
#endregion
}
#region タイプコンバーター
internal class SpreadRowConverter : ExpandableObjectConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(string)) return true;
if (destinationType == typeof(InstanceDescriptor)) return true;
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context,
System.Globalization.CultureInfo culture, object value, Type destType)
{
if (destType == typeof(string) && value is SpreadRow)
{
SpreadRow ic = (SpreadRow)value;
string rowtring = "" ;
if ( ic.HeaderText.Length != 0 )
{
rowtring += ic.HeaderText ;
}
return rowtring ;
}
if (destType == typeof(InstanceDescriptor) && value is SpreadRow)
{
SpreadRow ic = (SpreadRow)value;
System.Reflection.ConstructorInfo ctor = typeof(SpreadRow).GetConstructor(new Type[] {
typeof(string), typeof(Font), typeof(Color), typeof(Color) } ) ;
if (ctor != null)
{
return new InstanceDescriptor(ctor,
new object[] {ic.HeaderText, ic.HeaderFont, ic.HeaderForeColor, ic.HeaderBackColor}) ;
}
}
return base.ConvertTo(context, culture, value, destType);
}
}
#endregion
}