简体   繁体   English

哪种设计模式可以管理Windows?

[英]Which design pattern to manage windows?

I am using .NET 2.0 & C# to develop a WinForm Mdi application. 我正在使用.NET 2.0和C#开发WinForm Mdi应用程序。 It will have a Main Window and a lot of mdi windows. 它将有一个主窗口和许多mdi窗口。 I am thinking I should use which design pattern to manage mdi windows. 我在想应该使用哪种设计模式来管理MDI窗口。 Because I want only one instance for each window, if window is existed, I will show it on top, & otherwise I will create and show it. 因为每个窗口只需要一个实例,所以如果存在窗口,则将其显示在顶部,否则将创建并显示它。

Note: a mdi window is opened from Menus of Main Window or open from another mdi window. 注意:从主窗口的菜单中打开一个mdi窗口,或从另一个mdi窗口中打开。 An example is very good. 一个例子是非常好的。

Update: Menu's status is depended on mdi window's status. 更新:菜单的状态取决于mdi窗口的状态。 Ex: If Window 'A' is openned -> menu 'A' -> disabled. 例如:如果打开窗口“ A”->菜单“ A”->禁用。 When window 'A' is closed -> I update menu 'A' status to Enabled. 当窗口“ A”关闭时->我将菜单“ A”状态更新为“启用”。

Thanks. 谢谢。

I would suggest a good perusal of Martin Fowler's page on GUI Patterns. 我建议您仔细阅读Martin Fowler关于GUI模式的页面。

You won't find a quick example, but then again the problem set doesn't warrant a quick solution. 您不会找到快速的示例,但是问题集并不能保证快速的解决方案。 You need to spend some time understanding the different UI design patterns available and make an informed decision about which one will work best in your application. 您需要花费一些时间来了解可用的不同UI设计模式,并做出明智的决定,以确定哪种模式最适合您的应用程序。

Martin Fowler's site will give you enough information to begin your journey at least. Martin Fowler的网站将为您提供足够的信息,至少可以开始您的旅程。 You can dive perhaps a little deeper by looking over Jeremy Miller's series to get specific .Net examples. 通过查看Jeremy Miller的系列文章以获得特定的.Net示例,您可以深入研究。

Again, there won't be a quick fix around either of those corners, but it will be worth it to learn from industry leaders. 同样,在这两个方面都不会很快解决,但值得向行业领导者学习。

I dont think you will find one pattern to solve the problem, but will be a collaboration of pattern. 我认为您不会找到一种解决问题的模式,但是会成为一种模式的协作。 The links provided by Josh are interesting read. Josh提供的链接很有趣。

A simple suggestion based on GoF pattern will be as below: 基于GoF模式的简单建议如下:

  • Use Command pattern to handle your menu click event 使用命令模式来处理菜单单击事件
  • Use Factory pattern to create your window. 使用Factory模式创建窗口。 You can custom your factory so that it creates only single instance of the window, using approach from Singleton pattern 您可以使用Singleton模式中的方法来自定义工厂,使其仅创建窗口的单个实例
  • Use Subject-Observer pattern for the menu state. 将“主题观察者”模式用于菜单状态。 The MDI child window will be the subject and you will need to structure your code so that you can embedded observer logic in your menu controller. MDI子窗口将成为主题,您将需要构建代码结构,以便可以将观察者逻辑嵌入到菜单控制器中。

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

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