private DeserializeDockContent m_deserializeDockContent = new DeserializeDockContent(GetContentFromPersistString);
/// <summary>
/// 配置委托函数
/// </summary>
/// <param name="persistString"></param>
/// <returns></returns>
private static IDockContent GetContentFromPersistString(string persistString)
{
if (persistString == typeof(TreeViewForm).ToString())
{
return _treeViewForm;
}
else if (persistString == typeof(TimeWindowViewForm).ToString())
{
return _timeWindowViewForm;
}
else if (persistString == typeof(StartPageForm).ToString())
return _startPageForm;
else if (persistString == typeof(MapViewForm).ToString())
return _mapViewForm;
else if (persistString == typeof(DetailViewForm).ToString())
return _detailViewForm;
else
{
return null;
}
}
然后在主界面的Load事件中加上如下代码:
string configFile = Path.Combine(Properties.Settings.Default.TempPath, "DockPanel.config");
if (File.Exists(configFile))
{
dpnMain.LoadFromXml(configFile, m_deserializeDockContent);
}
在Close事件中加上保存即可,代码如下:
string configFile = Path.Combine(Properties.Settings.Default.TempPath, "DockPanel.config");
dpnMain.SaveAsXml(configFile);
/// <summary>
/// 配置委托函数
/// </summary>
/// <param name="persistString"></param>
/// <returns></returns>
private static IDockContent GetContentFromPersistString(string persistString)
{
if (persistString == typeof(TreeViewForm).ToString())
{
return _treeViewForm;
}
else if (persistString == typeof(TimeWindowViewForm).ToString())
{
return _timeWindowViewForm;
}
else if (persistString == typeof(StartPageForm).ToString())
return _startPageForm;
else if (persistString == typeof(MapViewForm).ToString())
return _mapViewForm;
else if (persistString == typeof(DetailViewForm).ToString())
return _detailViewForm;
else
{
return null;
}
}
然后在主界面的Load事件中加上如下代码:
string configFile = Path.Combine(Properties.Settings.Default.TempPath, "DockPanel.config");
if (File.Exists(configFile))
{
dpnMain.LoadFromXml(configFile, m_deserializeDockContent);
}
在Close事件中加上保存即可,代码如下:
string configFile = Path.Combine(Properties.Settings.Default.TempPath, "DockPanel.config");
dpnMain.SaveAsXml(configFile);