以前的表单隐藏/关闭winforms应用程序中的用户控件问题 [英] Previous Form hide/close problem with user control in winforms application

查看:82
本文介绍了以前的表单隐藏/关闭winforms应用程序中的用户控件问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用用户控件将一个表单导航到另一个表单时,如何在Windows窗体应用程序中隐藏或关闭以前的winform。

How can i hide or close previous winform in windows forms application when i am using user control to navigate one form to another.

推荐答案

是的,您可以:

http://msdn.microsoft。 com / en-us / library / system.windows.forms.control.show.aspx [ ^ ],

http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx [ ^ ]。



但是,在表单之间实现顺序导航这是一个非常糟糕的主意,特别是如果隐藏表单是主要表单。首先,没有先前形式的内在概念。你应该自己组织序列。现在,如果隐藏的表单是主要表单,关闭其他表单将不会关闭应用程序,因此您需要关心它。哪个表单是main是由一个 Application.Run 的参数定义的。如果退出应用程序(在此单词的UI意义上,而不是作为进程的应用程序),然后再调用另一个 Application.Run ,则可以更改它。有时使用这种技术,但更多用于在真实主要形式之前显示屏幕闪光。使用这种类似向导的UI技术(不是你想要的吗?)会使组织步骤和其他非线性步骤变得困难。



所以,最好的方法是这样:只使用一个表单(我不计算少量的模态(类似对话框)表单,你可以有几个)。不要使用一系列单独的表单,而是将它们转换为整个表单区域的面板(或者,除了带有导航按钮或其他导航控件的某些控制面板之外的区域)。在这种情况下,您可以通过隐藏除一个之外的所有此类页面面板来导航。导航将控制这些面板的可见性,一次显示一个。



实际上,这种方法比其他方法更灵活,但最容易实现。 />


-SA
Yes, you can:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.show.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx[^].

However, this is a pretty bad idea of implementing sequential navigation between forms, especially if a hidden form is a main one. First of all, there is no such intrinsic notion as "previous" form. You should organize the sequence by yourself. Now, if the hidden form is a main one, closing of other forms won't close the application, so you would need to care about it. Which form is main is defined by the one used s a parameter of Application.Run. You can change it if you exit the application (in the UI sense of this word, not application as a process) and then call another Application.Run. Such technique is sometimes used, but more for showing a screen flash before "real" main form. Using such technique for wizard-like UI (isn't it what you want?) would make it difficult to organize steps back and other non-linear steps.

So, the best approach is this: use only one form (I don't count small number of modal (dialog-like) forms, you can have a few). Instead of having a sequence of separate form, turn them into panels taking the whole form area (or, perhaps, the area except some control panel with navigation buttons or other navigation controls). In this case, you "navigate" by hiding all such "page" panels except one. Navigation will be a control over visibility of those panels, showing one at a time.

Really, this approach is more flexible than others, yet easiest to implement.

—SA


这篇关于以前的表单隐藏/关闭winforms应用程序中的用户控件问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆