从子表单关闭父表单 [英] Close parent form from child form

查看:73
本文介绍了从子表单关闭父表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大问题,我在智能设备应用程序上工作。我有3个表格。



i有3个表格



form1做这个动作

Hi, i have a big problem, i work on a smart device application. i had 3 forms.

i have 3 forms

the form1 do this action

{
            Form2 f = new Form2();
            f.ShowDialog();





form2执行此操作



the form2 do this action

Form3 f = new Form3();
          f.ShowDialog();





现在是form3 hase 2按钮。

i想要第一个按钮来解决我的问题form1

和seconde按钮显示form2



for seconde按钮我很容易就这样做



now the form3 hase 2 button.
i want the first button to didplay me the form1
and the seconde button to display the form2

for the seconde button it easy i do just this

this.close()





但是第一个按钮我不喜欢我不知道如何把我带到表格1

请帮助



i使用visual studio 2008智能设备紧凑型框架C#



我的尝试:



我有一个大问题,我致力于智能设备应用。 ihad表格。



i有3种表格



form1做这个动作



but for the first button i don't know how to do to bring me to the form1
please help

i use visual studio 2008 smart device compact framwork C#

What I have tried:

Hi, i have a big problem, i work on a smart device application. ihad forms.

i have 3 forms

the form1 do this action

{
            Form2 f = new Form2();
            f.ShowDialog();





form2执行此操作



the form2 do this action

Form3 f = new Form3();
          f.ShowDialog();





现在是form3 hase 2按钮。

i想要第一个按钮来解决我的问题form1

和seconde按钮显示form2



for seconde按钮我很容易就这样做



now the form3 hase 2 button.
i want the first button to didplay me the form1
and the seconde button to display the form2

for the seconde button it easy i do just this

this.close()





但是第一个按钮我不喜欢我不知道如何把我带到表格1

请帮助



i使用visual studio 2008智能设备紧凑的框架C#



but for the first button i don't know how to do to bring me to the form1
please help

i use visual studio 2008 smart device compact framwork C#

推荐答案

这样做会严重滥用UI。不要这样做。即使你成功实现了这种行为,大多数用户都会讨厌它,因为人们从不期待这样的伎俩。想象一下,如果他们想要保留您想要关闭的表格中输入的一些数据,会发生什么?你会意外地关闭它,失去控制的状态。这不是不再使用你的应用程序的唯一原因。


一些背景:即使在<$ c $的实例之间存在正式的父子关系c> System.Windows.Forms.Control ,默认情况下,对于继承相关属性的表单,此关系将被解除。你可以改变它,但它没有任何实际意义。主表单和其他表单之间存在关系,并且非常有用的所有权关系。



您的问题与一个非常不同的方面有关:通过<显示的表单的模态行为code> Form.ShowDialog ;它与亲子关系无关。这种行为的整个想法是:当这种形式处于模态状态时,您无法访问UI的任何其他部分。你永远不应该尝试通过某些技巧来打破这种行为。此外,有可能,但非常不希望堆叠多个模态形式,一个在另一个之上。许多Microsoft对话框仍然会执行此类操作,尤其是在控制面板中,但是遵循这种不良模型行为是一个坏主意。最好一次显示不超过一种模态形式,并限制此类形式的数量。请记住,完美的用户界面根本没有模态状态;但在某些情况下实施起来有点困难。



如果你解释了你的最终目的,你可能会得到进一步的建议。



-SA
Doing so would be serious UI abuse. Don't do it. Even if you successfully implemented such behavior, most users would hate it, because people never expect such tricks. Imagine what happens if they want to preserve some data entered in the form you want to close; and you will unexpectedly close it, losing the states of controls. And this is not the only reason for not using your application anymore.

Some background: even though there is a formal parent-child relationship between instances of System.Windows.Forms.Control, this relationship, by default, is rendered defunct for forms which inherit related properties. You could change it, but it would make no practical sense. There is relationship between main form and other forms, and very useful ownership relationship.

Your issue is related to a very different aspect: modal behavior of the forms shown via Form.ShowDialog; it has nothing to do with the parent-child relationship. The whole idea of this behavior is: you cannot access any other part of UI while such form is in the modal state. You should never try to break this behavior by some kinds of tricks. Moreover, it's possible, but really undesirable to stack more than one modal forms, one on top of another. Many Microsoft dialogs still do such things, especially in Control Panel, but following this poor model behavior is a bad idea. Better show no more than one modal form at a time, and limit the number of such forms. Remember that perfect UI would have no modal states at all; but it's just a bit harder to implement in some cases.

If you explain your ultimate purpose, it's possible that you can get further advice.

—SA


这篇关于从子表单关闭父表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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