您的位置:首页 > 其它

控件属性中使用继承TypeConverter对Color[]与string进行转换

2007-05-18 17:07 447 查看
如果控件的属性是一个数组的时候,如何才能将对象保存下来,又如何将它解析出来呢?使用TypeConverter类可以实现这样的转换。比如今天我所遇到的就是Color[]转换到string保存,并从string解析出来。

控件的CustomColor属性如下定义:
private Color[] m_CustomColor = new Color[0];

[Category("Appearance"),
TypeConverter(typeof(ColorConverter)),
Description("自定义字符随机颜色。")]
public Color[] CustomColor
using System;
using System.Drawing;
using System.Globalization;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;

namespace FaibClass.WebControls
using System.Drawing;
using System.Web.UI.WebControls;

internal class Util
{
//将颜色转换为十六进制
internal static string ConvertToHexColor(Color c)
{
WebColorConverter wcc = new WebColorConverter();
return wcc.ConvertToString(c);
}

//将颜色转换为十六进制
internal static Color FromHexColor(string c)
{
WebColorConverter wcc = new WebColorConverter();
return (Color)wcc.ConvertFromString(c);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: