很好地关闭模态窗口的层次结构 [英] Closing down a hierarchy of modal windows nicely

查看:49
本文介绍了很好地关闭模态窗口的层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对不起,我不知道父级和

子表单的层次结构的正确描述。

我有一个主表单,可以模态打开子表单。这个子表单依次

以模态方式打开它自己的子表单。

我还有一个单独的线程运行来监控读卡器。如果

用户删除了该卡,那么该线程会回拨主表单告诉它该卡已被拉出的
。然后主要表格应该关闭所有孩子

离开主表格作为唯一一个打开的表格。

我如何干净利落地用尽可能少的代码请尽可能吗?我会

如果可能的话,我不想在所有表格中添加代码。

我想如果我关闭了孩子那么从主要形式的形式,这个

" child"会杀死自己的孩子。这没有发生。

" child"或其儿童或正在关闭。

当我以前在delphi中编码时,当孩子被建造时,所有者将永远传给孩子

,并且孩子会将自己添加到其中业主

控制清单。我假设这不会发生在这里

我也尝试更改每个表单的构造函数,以便每个表单将

添加到它的所有者OwnedForm列表中。这也没有用,非常好。

凌乱。


谢谢

Im sorry, I dont know the correct description for a hierarchy of parent and
child forms.
I have a main form that opens a child form modally. This child form in turn
opens it''s own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any children
leaving the main form as the only one that''s open.
How do i do this cleanly and with as little code as possible please? I''d
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delp the owner would always be passed to a child
when the child was constructed, and the child would add itself to its owners
Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form would
add itself to it''s owners OwnedForm list. This also didnt work and was very
messy.

thank you

推荐答案




当您在对所拥有的表单的引用中调用Show方法传递时(

将设置Form.Owner物业):


表格表格=新表格();

form.Show(this);


我用过这个因为我假设上面的代码将在Form的上下文中执行

。例如,事件处理程序。如果没有,你将获得

来传递对主表格的引用。


-

Dave Sexton


" Chukkalove" < so ***** @ microsoft.comwrote in message

news:ug ************** @ TK2MSFTNGP03.phx.gbl ...
Hi,

When you call the Show method pass in a reference to the owning form (it
will set the Form.Owner property):

Form form = new Form();
form.Show(this);

I''ve used "this" because I''m assuming that the code above will be executing
within the context of a Form. e.g., an event handler. If not, you''ll have
to pass in a reference to the main Form.

--
Dave Sexton

"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...

对不起,我不知道父母层次结构的正确描述

和子表格。

我有一个以模态方式打开子表单的主窗体。这个孩子形式在

中以模态方式打开它自己的子表格。

我还有一个单独的线程运行来监控读卡器。如果

用户删除了该卡,那么该线程会回拨主表单告诉它该卡已被拉出的
。然后主要表格应该关闭任何

孩子离开主表单作为唯一一个打开的表单。

我如何干净利落地使用尽可能少的代码请尽可能吗?我会

如果可能的话,我不想在所有表格中添加代码。

我想如果我关闭了孩子那么从主要形式的形式,这个

" child"会杀死自己的孩子。这没有发生。

" child"或其儿童或正在关闭。

当我以前在delphi中编码时,当孩子被建造时,所有者将永远传给孩子

,并且孩子会将自己添加到其中

所有者控制列表。我假设这不会发生在这里

我也尝试更改每个表单的构造函数,以便每个表单

将自己添加到它的所有者OwnedForm列表中。这也没有用,

非常凌乱。


谢谢
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it''s own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that''s open.
How do i do this cleanly and with as little code as possible please? I''d
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delp the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it''s owners OwnedForm list. This also didnt work and
was very messy.

thank you





对不起,但我没有意识到你写的是模态。


而不是调用Show(this)调用ShowDialog(this)。


要关闭链中的所有模态表单,每个表单必须保存对

子的引用。模态形式它正在显示。然后将以下代码添加到每个表单:


protected override void OnClosing(CancelEventArgs e)

{

if(subModalForm! = null)

//关闭此表单显示的模式表格

subModalForm.Close();


base。 OnClosing(e);

}


要启动连锁反应并关闭所有打开的模态对话框,请调用Close()

在第一张表格上。


-

Dave Sexton


" Chukkalove" < so ***** @ microsoft.comwrote in message

news:ug ************** @ TK2MSFTNGP03.phx.gbl ...
Hi,

Sorry, but I didn''t realize that you wrote, "modal".

Instead of calling Show(this) call ShowDialog(this).

To close all modal Forms in a chain, each Form must save a reference to the
sub-modal Form that it''s showing. Then add the following code to each Form:

protected override void OnClosing(CancelEventArgs e)
{
if (subModalForm != null)
// close the modal Form being shown by this Form
subModalForm.Close();

base.OnClosing(e);
}

To start the chain-reaction and close all open modal dialogs, call Close()
on the first Form.

--
Dave Sexton

"Chukkalove" <so*****@microsoft.comwrote in message
news:ug**************@TK2MSFTNGP03.phx.gbl...

对不起,我不知道父母层级的正确描述

和子表格。

我有一个以模态方式打开子表单的主窗体。这个孩子形式在

中以模态方式打开它自己的子表格。

我还有一个单独的线程运行来监控读卡器。如果

用户删除了该卡,那么该线程会回拨主表单告诉它该卡已被拉出的
。然后主要表格应该关闭任何

孩子离开主表单作为唯一一个打开的表单。

我如何干净利落地使用尽可能少的代码请尽可能吗?我会

如果可能的话,我不想在所有表格中添加代码。

我想如果我关闭了孩子那么从主要形式的形式,这个

" child"会杀死自己的孩子。这没有发生。

" child"或其儿童或正在关闭。

当我以前在delphi中编码时,当孩子被建造时,所有者将永远传给孩子

,并且孩子会将自己添加到其中

所有者控制列表。我假设这不会发生在这里

我也尝试更改每个表单的构造函数,以便每个表单

将自己添加到它的所有者OwnedForm列表中。这也没有用,

非常凌乱。


谢谢
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it''s own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that''s open.
How do i do this cleanly and with as little code as possible please? I''d
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delp the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it''s owners OwnedForm list. This also didnt work and
was very messy.

thank you





我认为你不需要引用subModalForm而你

不必打电话给关闭() 在上面。当你使用ShowDiaglog(这个),

第一个窗口上的close()会做;孩子们将被关闭(并且将触发他们所有活动的
)。或者我错过了什么?


11月21日晚上9点07分,Dave Sexton < dave @jwa [remove.this] online.com>

写道:
Hi,

I don''t think you need to have a reference to subModalForm and you
don''t have to call close() on it. When you are using ShowDiaglog(this),
a close() on the first window will do; the children will be closed (and
all their events will be triggered). Or am i missing something?

On Nov 21, 9:07 pm, "Dave Sexton" <dave@jwa[remove.this]online.com>
wrote:




对不起,但我没有意识到你写的是模态。


而不是调用Show(this)调用ShowDialog(this)。


要关闭链中的所有模态表单,每个表单必须保存对它所显示的

子模式表单的引用。然后将以下代码添加到每个表单:


protected override void OnClosing(CancelEventArgs e)

{

if(subModalForm! = null)

//关闭此表单显示的模式表格

subModalForm.Close();


base。 OnClosing(e);


}要启动链式反应并关闭所有打开的模态对话框,请在第一个Form上调用Close()

。 />

-

Dave Sexton


" Chukkalove" < some ... @ microsoft.comwrote in messagenews:ug ************** @ TK2MSFTNGP03.phx.gbl。 ..
Hi,

Sorry, but I didn''t realize that you wrote, "modal".

Instead of calling Show(this) call ShowDialog(this).

To close all modal Forms in a chain, each Form must save a reference to the
sub-modal Form that it''s showing. Then add the following code to each Form:

protected override void OnClosing(CancelEventArgs e)
{
if (subModalForm != null)
// close the modal Form being shown by this Form
subModalForm.Close();

base.OnClosing(e);

}To start the chain-reaction and close all open modal dialogs, call Close()
on the first Form.

--
Dave Sexton

"Chukkalove" <some...@microsoft.comwrote in messagenews:ug**************@TK2MSFTNGP03.phx.gbl. ..

对不起,我不知道父母层次结构的正确描述

和子表格。

我有一个主窗体,可以模态打开子窗体。这个孩子形式在

中以模态方式打开它自己的子表格。

我还有一个单独的线程运行来监控读卡器。如果

用户删除了该卡,那么该线程会回拨主表单告诉它该卡已被拉出的
。然后主要表格应该关闭任何

孩子离开主表单作为唯一一个打开的表单。

我如何干净利落地使用尽可能少的代码请尽可能吗?我会

如果可能的话,我不想在所有表格中添加代码。

我想如果我关闭了孩子那么从主要形式的形式,这个

" child"会杀死自己的孩子。这没有发生。

" child"或其儿童或正在关闭。

当我以前在delphi中编码时,当孩子被建造时,所有者将永远传给孩子

,并且孩子会将自己添加到其中

所有者控制列表。我假设这不会发生在这里

我也尝试更改每个表单的构造函数,以便每个表单

将自己添加到它的所有者OwnedForm列表中。这也没有用,

非常混乱。
Im sorry, I dont know the correct description for a hierarchy of parent
and child forms.
I have a main form that opens a child form modally. This child form in
turn opens it''s own child form modally.
I also have a separate thread running that monitors a card reader. If the
user removes the card then the thread calls back the main form to tell it
that the card was pulled. The main form should then close down any
children leaving the main form as the only one that''s open.
How do i do this cleanly and with as little code as possible please? I''d
prefer not to have to add code to all the forms if possible.
I thought that if I closed the "child" form from the main form, that this
"child" would kill its own "children". This isnt happening. Neither the
"child" or its "children" are closing.
When i used to code in delp the owner would always be passed to a child
when the child was constructed, and the child would add itself to its
owners Controls list. I assume this isnt happening here
I also tried changing the constructor for every form so that each form
would add itself to it''s owners OwnedForm list. This also didnt work and
was very messy.


谢谢
thank you


这篇关于很好地关闭模态窗口的层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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