简体   繁体   English

C# - WinForms - SDI 或 MDI 方法?

[英]C# - WinForms - SDI or MDI Approach?

I am creating a Visual C# WinForms application that will contain 4 forms:我正在创建一个 Visual C# WinForms 应用程序,它将包含 4 个 forms:

  1. A "control" form that will have anywhere between 2 buttons and potentially up to 10 or so.一个“控制”表单,将有 2 个按钮,可能多达 10 个左右。 So the screen will need to accommodate enough space for the maximum amount of buttons.因此屏幕需要为最大数量的按钮提供足够的空间。
  2. A "logging" form that will contain a large rich textbox control.将包含大型富文本框控件的“日志记录”表单。
  3. A "config" form that will contain a tab control with various configuration settings that can be tweaked.一个“配置”表单,其中包含一个选项卡控件,其中包含可以调整的各种配置设置。
  4. A "order log" form that's very similar to #2.与#2 非常相似的“订单日志”表单。

It's likely that the user will want to reposition each of these forms in different ways.用户可能希望以不同的方式重新定位每个 forms。 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.然而,我希望这些 forms 由父表单“管理”,这样当应用程序关闭时,所有其他 forms 都会关闭。 Is there a way to keep the MDI approach, yet allow the child forms move outside of the parent form using C# WinForms?有没有办法保持 MDI 方法,但允许子 forms 使用 C# WinForms 移出父表单? Thanks!谢谢!

usually for such cases you would use the "docking" feature.通常对于这种情况,您会使用“对接”功能。 same way is done in Visual Studio itself.在 Visual Studio 本身中也是如此。 This way user can hide/show very easy the forms.通过这种方式,用户可以非常轻松地隐藏/显示 forms。

Such a package doesn't come with Visual Studio, but there are free libraries for this. Visual Studio 不附带这样的 package,但是有免费的库。 Check this out http://sdock.codeplex.com/ for example.例如,查看http://sdock.codeplex.com/

You can do just about anything you want.你可以做任何你想做的事。

You can establish a parent-child relationships between the forms. forms之间可以建立父子关系。 Or, if you want, you can explicity close the other forms when the main form is closed.或者,如果您愿意,您可以在主窗体关闭时明确关闭另一个 forms。

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(例如 Office),因此即使您有多个 forms,我也可能会使用带有 SDI 样式接口的 go。 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. MDI 往往没有很好地利用屏幕空间,大多数现代用户不习惯处理它的一些怪癖。

I have worked with MDI applications a bit and have tried something similar.我曾经使用过一些 MDI 应用程序并尝试过类似的东西。

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.我注意到 MDI 的一件事是 forms 和控件的绘制速度似乎比常规的 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.关于 MDI 的另一件事是您的孩子 windows 将包含在父 window 中,这适用于某些应用程序,但对其他人来说很烦人。

Another quirk with MDI is that you cannot use window transparency, if you have such a need for that. MDI 的另一个怪癖是,如果您有这样的需要,您不能使用 window 透明度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM