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

发布于 2024-08-07 03:13:26 字数 103 浏览 2 评论 0原文

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

I'm writing an MDI Application in C#. I'd like a way to store the positions and contents of all the open windows, so that a user can customize the way multiple documents are viewed. Is there a simple way to do this, or will I have to roll my own solution?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

人间不值得 2024-08-14 03:13:26

我见过一些形式的持久性类,但它们并没有完全满足我的需要。我最终推出了自己的版本,主要执行以下操作:

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() 方法,它本质上反转了该过程,询问保存的设置,设置值。可能有一种更优雅的解决方案来解决这个问题,但这个解决方案对我来说非常有效。

希望有帮助。

I've seen a few form persistence classes around but they didn't do exactly what I needed. I ended up rolling my own, essentially doing the following:

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() just stores this info off in some XML file in the user's space, but you could store it differently, of course.

When appropriate, such as at startup, I have a ReadSettings() method that essentially reverses the process, interrogating the saved settings, setting the values. There might be a more elegant solution to the problem, but this one has worked really well for me.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文