如果不是序列化的话,你恐怕永远保存不了字体与颜色的所有信息
字体与颜色的序列化参考
对于没有序列化属性的对象进行序列化时采用如下序列方法:(几个方法)
public static byte[] SerializeObject(object pObj)
{
if(pObj == null)
return null;
System.IO.MemoryStream _memory = new System.IO.MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(_memory,pObj);
_memory.Position = 0;
byte[] read = new byte[_memory.Length];
_memory.Read(read,0,read.Length);
_memory.Close();
return read;
}
public static void SerializeObject(object pObj,string pFileName)
{
System.IO.FileStream stream = System.IO.File.Open(pFileName,System.IO.FileMode.Create,System.IO.FileAccess.Write);
byte[] bytes = SerializeObject(pObj);
stream.Write(bytes,0,bytes.Length);
stream.Flush();
stream.Close();
}
字体与颜色的序列化参考
对于没有序列化属性的对象进行序列化时采用如下序列方法:(几个方法)
public static byte[] SerializeObject(object pObj)
{
if(pObj == null)
return null;
System.IO.MemoryStream _memory = new System.IO.MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();
formatter.Serialize(_memory,pObj);
_memory.Position = 0;
byte[] read = new byte[_memory.Length];
_memory.Read(read,0,read.Length);
_memory.Close();
return read;
}
public static void SerializeObject(object pObj,string pFileName)
{
System.IO.FileStream stream = System.IO.File.Open(pFileName,System.IO.FileMode.Create,System.IO.FileAccess.Write);
byte[] bytes = SerializeObject(pObj);
stream.Write(bytes,0,bytes.Length);
stream.Flush();
stream.Close();
}
public static object DeserializeObject(string pFileName)
{
System.IO.FileStream stream = System.IO.File.Open(pFileName,System.IO.FileMode.Open,System.IO.FileAccess.Read);
byte[] bytes = new byte[stream.Length];
stream.Read(bytes,0,bytes.Length);
stream.Close();
return DeserializeObject(bytes);
}
public static object DeserializeObject(byte[] pBytes)
{
object _newOjb = null;
if(pBytes == null)
return _newOjb;
System.IO.MemoryStream _memory = new System.IO.MemoryStream(pBytes);
_memory.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
_newOjb = formatter.Deserialize(_memory);
_memory.Close();
return _newOjb;
}
取回来:Color.FromArgb(int.Parse(temp ))
Font.Name;
Font.Size;.......回写:xx.Font = new Font(Name,Size);
xx.Font = new Font(xx.Font,xx.Font.Style|Font.Style.UnderLine);
.....
xx.Font = new Font(xx.Font,xx.Font.Style|FontStyle.UnderLine);
不知楼主要的是不是这个
我只是觉得序列化比较麻烦,因为我的数据中涉及对象太多了to xum1983:
Font.Style可以拆开了存再回写吗,如果不行的话可能还的用序列化过两天就揭贴,看还有其它新发现没有
Font.Style可以拆开了存再回写吗,如果不行的话可能还的用序列化过两天就揭贴,看还有其它新发现没有这个我做过
[email protected]