如何在.NET中保留MDI布局?

时间:2009-09-30 13:12:00

标签: c# .net mdi

我正在用C#编写MDI应用程序。我想要一种存储所有打开窗口的位置和内容的方法,以便用户可以自定义查看多个文档的方式。有一种简单的方法可以做到这一点,还是我必须推出自己的解决方案?

1 个答案:

答案 0 :(得分:1)

我已经看到了一些形式的持久化类,但它们并没有完全符合我的需要。我最终完成了自己的工作,基本上做了以下几点:

Control mdiClientControl;
foreach (Control control in Controls)
{
   if (control is MdiClient)
   {
      mdiClientControl = control;
      break;
   }
}

foreach (Form mdiChild in MdiChildren)
{
   string theName = mdiChild.Name + "_Window_Layout";
   DoSave(theName, "Top", mdiChildTop);
   .
   .
   .
   DoSave(theName, "WindowState", (int)mdiChild.WindowState);
   DoSave(theName, "Visible", mdiChild.Visible);
   DoSave(theName, "ChildIndex", theMDIClientControl.Controls.GetChildIndex(mdiChild));
}

DoSave()只是将这些信息存储在用户空间的某个XML文件中,但当然可以以不同方式存储它。

在适当的时候,例如在启动时,我有一个ReadSettings()方法,它基本上会反转过程,询问保存的设置,设置值。可能有一个更优雅的解决方案,但这个问题对我来说非常好。

希望有所帮助。

相关问题