C# - WinForms - SDI 或 MDI 方法?
我正在创建一个 Visual C# WinForms 应用程序,它将包含 4 个表单:
- 一个“控件”表单,包含 2 个按钮,最多可能有 10 个按钮。因此,屏幕需要为最大数量的按钮提供足够的空间。
- 一个“日志记录”表单,将包含一个大型的富文本框控件。
- “配置”表单将包含一个选项卡控件,其中包含可以调整的各种配置设置。
- 与 #2 非常相似的“订单日志”表单。
用户可能希望以不同的方式重新定位每个表单。然而,我希望这些表单由父表单“管理”,以便当应用程序关闭时,所有其他表单都会关闭。有没有办法保留 MDI 方法,同时允许使用 C# WinForms 将子窗体移动到父窗体之外?谢谢!
I am creating a Visual C# WinForms application that will contain 4 forms:
- A "control" form that will have anywhere between 2 buttons and potentially up to 10 or so. So the screen will need to accommodate enough space for the maximum amount of buttons.
- A "logging" form that will contain a large rich textbox control.
- A "config" form that will contain a tab control with various configuration settings that can be tweaked.
- A "order log" form that's very similar to #2.
It's likely that the user will want to reposition each of these forms in different ways. Yet, I would like these forms to be "managed" by a parent form so that when the application closes, all of the other forms close. Is there a way to keep the MDI approach, yet allow the child forms move outside of the parent form using C# WinForms? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常在这种情况下,您会使用“对接”功能。 Visual Studio 本身也采用同样的方法。这样用户可以非常轻松地隐藏/显示表单。
Visual Studio 不附带这样的包,但有免费的库。例如,请查看 http://sdock.codeplex.com/ 。
usually for such cases you would use the "docking" feature. same way is done in Visual Studio itself. This way user can hide/show very easy the forms.
Such a package doesn't come with Visual Studio, but there are free libraries for this. Check this out http://sdock.codeplex.com/ for example.
我曾经使用过 MDI 应用程序并尝试过类似的操作。
我从经验中学到了一些事情,您在做出决定之前应该考虑一下。
我注意到 MDI 的一件事是,窗体和控件的绘制速度似乎比常规窗体慢一些。因此,当您单击链接/按钮并抛出一个新的子表单时,您可以看到它在视觉上将新的子表单绘制到屏幕上,这使您的应用程序显得缓慢。这已经在大量硬件/操作系统组合和测试应用程序上进行了测试,这些测试应用程序除了打开带有一些控件的表单外不执行任何操作。
关于 MDI 的另一件事是您的子窗口将包含在父窗口中,这对某些应用程序有效,但对其他应用程序来说很烦人。
MDI 的另一个怪癖是,如果您有这样的需要,则无法使用窗口透明度。
I have worked with MDI applications a bit and have tried something similar.
There are a few things I have learned from experience that you should consider before you decide.
One thing I have noticed with MDI's is that the forms and controls seem to paint a little slower than regular forms. So when you click a link/button and throw up a new child form, you can see it visually paint the new child form onto the screen, which makes your application seem sluggish. This has been tested on a huge host of hardware/OS combinations and with test applications that aren't doing anything but opening a form with some controls on it.
Another thing about MDI is your child windows will be contained within the parent window, which works for some applications, but is annoying for others.
Another quirk with MDI is that you cannot use window transparency, if you have such a need for that.
你几乎可以做任何你想做的事。
您可以在表单之间建立父子关系。或者,如果您愿意,您可以在关闭主窗体时显式关闭其他窗体。
大多数系统正在逐渐放弃 MDI(例如 Office),因此我可能会使用 SDI 风格的界面,即使您有多种表单。 MDI 往往无法充分利用屏幕空间,并且大多数现代用户不习惯处理它的一些怪癖。
You can do just about anything you want.
You can establish a parent-child relationships between the forms. Or, if you want, you can explicity close the other forms when the main form is closed.
Most systems are moving away from MDI (like Office for example), so I would probably go with an SDI-style interface, even if you have several forms. MDI tends to not make good use of the screen real-estate, and most modern users are not accustomed to dealing with some of its quirks.