110,499
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
namespace DockPanelTest
{
public partial class MainForm : Form
{
private Form1 f1 = new Form1();
private Form2 f2 = new Form2();
private Form3 f3 = new Form3();
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
f1.Show(dockPanel1);
f2.Show(dockPanel1);
f3.Show(dockPanel1);
string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
if (File.Exists(uiFile))
{
DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
dockPanel1.LoadFromXml(uiFile, ddContent);
}
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
dockPanel1.SaveAsXml(Path.Combine(Application.StartupPath, "CustomUI.xml"));
}
#region 加载布局
private IDockContent GetContentFromPersistString(string persistString)
{
try
{
if (persistString == typeof(Form1).ToString())
{
if (f1 == null)
{
return new Form1();
}
else
{
return f1;
}
}
if (persistString == typeof(Form2).ToString())
{
if (f2 == null)
{
return new Form2();
}
else
{
return f2;
}
}
if (persistString == typeof(Form3).ToString())
{
if (f3 == null)
{
return new Form3();
}
else
{
return f3;
}
}
}
catch (Exception ex)
{
Console.WriteLine(persistString);
}
throw new Exception();
}
#endregion
}
}
f1.Show(dockPanel1);
f2.Show(dockPanel1);
f3.Show(dockPanel1);
string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
if (File.Exists(uiFile))
{
DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
dockPanel1.LoadFromXml(uiFile, ddContent);
}
的位置有点问题,我改变一下就好了,修正如下:
string uiFile = Path.Combine(Application.StartupPath, "CustomUI.xml");
if (File.Exists(uiFile))
{
DeserializeDockContent ddContent = new DeserializeDockContent(GetContentFromPersistString);
dockPanel1.LoadFromXml(uiFile, ddContent);
}
f1.Show(dockPanel1);
f2.Show(dockPanel1);
f3.Show(dockPanel1);
这样就解决了,感谢,结贴了喔。