我想在图表中多次更改一些 Yvalues[0] 后恢复以前的系列。所以我使用备忘录模式实现了撤销操作。
但是它不起作用并且运行时没有错误。下面是发起人、纪念品和看守人。
public class Originator
{
private Series _series = new Series();
public Originator(Series series)
{
_series = series;
}
public Series OSeries
{
get
{
return _series;
}
set
{
_series = value;
}
}
public Memento SaveSeries()
{
return new Memento(_series);
}
public void RestoreSeries(Memento m)
{
this._series = m.MMseries;
}
}
public class Memento
{
private Series _series =new Series();
public Memento(Originator org)
{
this._series = org.OSeries;
}
public Memento(Series mseries)
{
_series = mseries;
}
public Series MMseries
{
get
{
return _series;
}
set
{
_series = value;
}
}
}
public class Caretaker
{
// private static Caretaker _instance;
// public Caretaker() { }
private Memento chartMemento;
public Memento Memento
{
get
{ return chartMemento; }
set
{ chartMemento = value; }
}
}
在公共部分类 Form1 中创建对象:Form
Originator _org;
Caretaker taker = new Caretaker();
从文件加载图表时,open_file 函数包含以下代码:
_org = new Originator(global_series); //For undo/redo operation
while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); }
chart1.Series.Add(global_series);
taker.Memento = _org.SaveSeries();
对于撤消按钮:
_org.RestoreSeries(taker.Memento);
while (chart1.Series.Count > 0) { chart1.Series.RemoveAt(0); }
global_series = _org.OSeries;
chart1.Series.Add(global_series);
MYYA
catspeake
相关分类