public class CustomStyleHelper
{
public static void DoSerialize(string strFile,CustomStyle customstyle)
{
using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
{
XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
formatter.Serialize(fs, customstyle);
}
}
public static CustomStyle DeSerialize(string strFile)
{
CustomStyle customstyle;
using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
customstyle = (CustomStyle)formatter.Deserialize(fs);
}
return customstyle;
}
//XML序列化方式不能序列化对象类型属性(比如Color),只能序列化int string类型属性
//Binary序列化方式可以序列化对象类型属性(比如Color),也能序列化int string类型属性
//zhangjun 2010.12.10
public static void BinaryDoSerialize(string strFile, CustomStyle customstyle)
{
using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, customstyle);
}
}
public static CustomStyle BinaryDeSerialize(string strFile)
{
CustomStyle customstyle;
using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
BinaryFormatter formatter = new BinaryFormatter();
customstyle = (CustomStyle)formatter.Deserialize(fs);
}
return customstyle;
}
public static IRgbColor Color2RgbColor(Color color)
{
IRgbColor NewColor = new RgbColor();
NewColor.Blue = color.B;
NewColor.Red = color.R;
NewColor.Green = color.G;
if (color.Name.ToUpper() == "TRANSPARENT")
{
NewColor.Transparency = 0;
}
return NewColor;
}
}
[Serializable]
public class CustomStyle
{
private Color sColor;
public Color SColor
{
get { return sColor; }
set { sColor = value; }
}
private double sWidth;
public double SWidth
{
get { return sWidth; }
set { sWidth = value; }
}
private Color dColor;
public Color DColor
{
get { return dColor; }
set { dColor = value; }
}
private double dWidth;
public double DWidth
{
get { return dWidth; }
set { dWidth = value; }
}
}
{
public static void DoSerialize(string strFile,CustomStyle customstyle)
{
using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
{
XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
formatter.Serialize(fs, customstyle);
}
}
public static CustomStyle DeSerialize(string strFile)
{
CustomStyle customstyle;
using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
XmlSerializer formatter = new XmlSerializer(typeof(CustomStyle));
customstyle = (CustomStyle)formatter.Deserialize(fs);
}
return customstyle;
}
//XML序列化方式不能序列化对象类型属性(比如Color),只能序列化int string类型属性
//Binary序列化方式可以序列化对象类型属性(比如Color),也能序列化int string类型属性
//zhangjun 2010.12.10
public static void BinaryDoSerialize(string strFile, CustomStyle customstyle)
{
using (FileStream fs = new FileStream(strFile, FileMode.OpenOrCreate))
{
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(fs, customstyle);
}
}
public static CustomStyle BinaryDeSerialize(string strFile)
{
CustomStyle customstyle;
using (FileStream fs = new FileStream(strFile, FileMode.Open))
{
BinaryFormatter formatter = new BinaryFormatter();
customstyle = (CustomStyle)formatter.Deserialize(fs);
}
return customstyle;
}
public static IRgbColor Color2RgbColor(Color color)
{
IRgbColor NewColor = new RgbColor();
NewColor.Blue = color.B;
NewColor.Red = color.R;
NewColor.Green = color.G;
if (color.Name.ToUpper() == "TRANSPARENT")
{
NewColor.Transparency = 0;
}
return NewColor;
}
}
[Serializable]
public class CustomStyle
{
private Color sColor;
public Color SColor
{
get { return sColor; }
set { sColor = value; }
}
private double sWidth;
public double SWidth
{
get { return sWidth; }
set { sWidth = value; }
}
private Color dColor;
public Color DColor
{
get { return dColor; }
set { dColor = value; }
}
private double dWidth;
public double DWidth
{
get { return dWidth; }
set { dWidth = value; }
}
}
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步