控件属性中使用继承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);
}
}
控件的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);
}
}
相关文章推荐
- JS 使用 Android + IOS 相册 + 相机 进行自定义头像 + 限制裁剪后图片尺寸 + base64 string 与 图片互相转换
- 使用BeanUtils设置属性转换String到Date类型
- 如何从 Datagrid 中获得单元格的内容与 使用值转换器进行绑定数据的转换IValueConverter
- C# 使用FileUpload控件上传图片,将文件转换成二进制进行存储与读取
- 对用户控件进行属性封装的使用情景分享(一)
- 使用stringstream 来进行string和其他类型的转换
- C#winform中使用控件的Dock属性进行布局
- 使用js进行string和json之间转换的方法
- 对用户控件进行属性封装的使用情景分享(二)
- 使用Spring Cloud微服务框架进行多个微服务整合时出现No converter found for return value of type:xxx异常信息
- WPF 使用值转换器进行绑定数据的转换IValueConverter
- 使用C++ stringstream来进行数据类型转换
- C++ 中使用sstream进行string和int相互转换
- 使用Solid Converter PDF控件把PDF转换至Word文档
- 使用stringstream对string进行类型转换
- 使用fastJson进行String与Object之间的转换
- JAVA使用jodatime进行date类型与string类型的时间相互转换
- vs2010 mfc项目配置属性的字符集为Unicode和多字节时,两者转换后使用的控件外观不一样
- struts2日期类型转换,继承StrutsTypeConverter