导航到新表单时关闭前一个表单. [英] Closing the previous form when navigating to a new one.

查看:104
本文介绍了导航到新表单时关闭前一个表单.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关Windows窗体应用程序的帮助.
说我有2种形式.我想离开我的父表单并转到子表单.问题是关闭父窗体.
使用this.close关闭所有表单.
任何想法如何做到这一点?谢谢.

我需要关闭第一个表单,因为我对其进行了编辑,以使其没有标题栏(因此没有最小化/最大化/关闭).这种方法的问题是它永远都不会关闭.

I need some help regarding windows form applications.
Say I have 2 forms. I want to navigate away from my parent form and move to a child form. The problem is closing the parent form.
Using this.close closes all forms.
Any idea how this is done? thank you.

I need to close the first form since I edited it so that it wouldn''t have a title bar (hence no minimize/maximize/close).. I need it that way. The problem with this way is that it never closes.

推荐答案

启动应用程序时,第一个Run()窗体被视为主窗体,关闭它会关闭该应用程序.

为什么只因为用户在应用程序中的另一个窗体上而需要关闭它,这对我来说还是个谜.

如果是因为您不想让用户在打开第二个窗体时又返回到主窗体,则使用Form2.ShowDialog()而不是Form2.Show()将第二个窗体设为Modal窗体.这样,您必须在Form2关闭之前才能访问您的主窗体.

如果还有其他原因,那么也许您可以编辑问题进行解释,以便获得相关的答案.
The first Form to Run() on starting an application is regarded as the Main Form and closing it will close the application.

Why you feel the need to close it just because the user is on another Form in the application is a mystery to me.

If it is because you do not want to allow the user to go back to the Main Form whilst the second Form is open, then make the second Form a Modal Form by using Form2.ShowDialog() instead of just Form2.Show(). That way your Main Form cannot be accessed until Form2 closes.

If there is another reason, then perhaps you could edit your question to explain it so that you get relevant answers.


尝试将父表单上的Visible属性设置为false而不是关闭它.您可能还需要管理任务栏中表单的可见性.
Try setting the Visible property on the parent form to false instead of closing it. You may also want to manage the visibility of the form in the taskbar.


这些不是父"和表单"!他们可能有也可能没有所有权关系:一种是主要形式,另一种是拥有形式".在两种情况下,这都是预期的行为.更改主窗体以再次调用Application.Run的方式(请参见入口点).您可以做到,您给了您食谱.建议是:无论如何都要避免

—SA
These are not "parent" and "forms"! They may or may not be in Ownership relationship: one in main form and the Owner of another "Owning Form". In both cases, this is expected behavior. The way to change main form it to call Application.Run (see your entry point) again. You can do it, you gave you the recipe. Advice is: avoid it by any means!

—SA


这篇关于导航到新表单时关闭前一个表单.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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