记录窗口上次关闭的位置和大小
///<summary>
/// 把字节数组反序列化成对象
///</summary>
public static object DeserializeObject(byte[] bytes)
{
object obj = null;
if (bytes == null)
return obj;
MemoryStream ms = new MemoryStream(bytes);
ms.Position = 0;
BinaryFormatter formatter = new BinaryFormatter();
try
{
obj = formatter.Deserialize(ms);
}
catch { obj = null; }
ms.Close();
return obj;
}
public static bool Save(string path, object value, bool isCeranew)
{
//如果不存在创建文件
FileStream fs;
if ((!File.Exists(path)) && isCeranew)
{
try
{
fs = File.Create(path);
}
catch
{
return false;
}
}
//如果存在则打开
else
{
try
{
fs = File.Open(path, FileMode.Open, FileAccess.Write);
}
catch
{
return false;
}
}
//写文件
byte[] buffer = SerializeObject(value);
try
{
for (long i = 0; i < buffer.LongLength; i++)
fs.WriteByte(buffer[i]);
}
catch
{
return false;
}
fs.Close();
return true;
}
public static object Read(string path)
{
FileStream fs;
try
{
fs = File.OpenRead(path);
}
catch
{
&nbs