using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;
namespace SdiAppSimple
{
///
/// Summary description for Doc1.
///
public class Doc1 : SdiTemplate.SdiDoc
{
private List ptList;
private Color backColor = Color.White;
public Doc1()
{
ptList = new List();
}
public void Add(Point pt)
{
ptList.Add(pt);
UpdateAllViews(null);
}
public List GetPoints()
{
return ptList;
}
public override void DeleteContents()
{
ptList.Clear();
base.DeleteContents ();
}
private IFormatter GetFormatter()
{
return new BinaryFormatter();
}
public void Serialize()
{
using (Stream stream = new FileStream("data.save", FileMode.Create))
{
IFormatter formatter = GetFormatter();
formatter.Serialize(stream, ptList);
formatter.Serialize(stream, backColor);
stream.Close();
}
}
public void Deserialize()
{
using (Stream stream = new FileStream("data.save", FileMode.Open))
{
IFormatter formatter = GetFormatter();
ptList = (List)formatter.Deserialize(stream);
backColor = (Color)formatter.Deserialize(stream);
stream.Close();
UpdateAllViews(null);
}
}
public Color BackColor
{
get { return backColor; }
set
{
backColor = value;
UpdateAllViews(null);
}
}
}
}