防止儿童MDI休假 [英] Prevent Child MDI leave

查看:70
本文介绍了防止儿童MDI休假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我想知道您是否可以在以下情况下为我提供帮助:
-我有一个MDI应用程序,子窗体打开/停留在主窗体中
-通过打开第一个孩子的表单(例如ChildForm-A)来打开2个孩子表单,然后打开另一个孩子的表单(例如ChildForm-B)
-现在我在ChildForm-B上填充数据并处理内容.
-假设某些数据无效(它们无法通过某些方式验证)
-现在尝试切换离开ChildForm-B的表单并转到ChildForm-A
-事件"MdiChildActivate"被触发,我进入父控件上的事件处理程序.
-触发此事件后,将在ChildForm-B上触发离开"事件,然后开始进行验证.
-只有那时我才知道该表单无效,并且我想保留在它上面(ChildForm-B),但是由于"MdiChildActivate"已被触发,所以现在我已经在另一种表单上了.
-现在,我可以保留在无效表单上的唯一方法是将其重新设置为活动子表单

-如果我尝试在2个MDI子窗体之间切换而又不准备形成A窗体,然后手动将活动的子窗体设置回B窗体,是否有办法避免留下无效的窗体

-预先感谢您的所有帮助.

Hello All,

I was wondering if you can help me with the following scenario:
- I have a MDI application, with the child forms opening / staying within the main parent form
- Open 2 child forms by opening a first child for (say ChildForm-A), then open another child form (say ChildForm-B)
- Now I''m filling data and processing stuff on ChildForm-B.
- Assume that some of the Data are invalid (they fail validation some how)
- Now try to switch forms leaving ChildForm-B and going to ChildForm-A
- The event "MdiChildActivate" is fired and I get to the event handler on the parent control.
- Once this event is fired, the "Leave" event is fired on ChildForm-B, and the validation kicks in.
- Only then I know that the Form is invalid, and I want to stay on it (ChildForm-B), however by now I''m already on the other form, since "MdiChildActivate" has been fired.
- Now, the only way I can stay on the invalid form, is to set it back as the active child

- Is there a way to prevent leaving the invalid form if I''m trying to switch between 2 MDI child forms without going to form A then manually set back the active child to form B

- Thank you in advance for all your help.

推荐答案

来自MSDN:

当您通过使用键盘(TAB,SHIFT + TAB等),通过调用Select或SelectNextControl方法或将ContainerControl .. ::.ActiveControl属性设置为当前形式来更改焦点时,将焦点事件按以下顺序发生:

1.输入
2.GotFocus
3.离开
4.验证
5.已验证
6.LostFocus

当您使用鼠标或调用Focus方法更改焦点时,焦点事件将按以下顺序发生:

1.输入
2.GotFocus
3.LostFocus
4.离开
5.验证
6.已验证

如果CausesValidation属性设置为false,则将抑制Validating和Validated事件.

如果在Validating事件委托中将CancelEventArgs的Cancel属性设置为true,则将取消所有在Validating事件之后通常发生的事件.


我相信所有ContainerControl都有一种方法方法来验证其自己的子控件.
From MSDN:

When you change the focus by using the keyboard (TAB, SHIFT+TAB, and so on), by calling the Select or SelectNextControl methods, or by setting the ContainerControl..::.ActiveControl property to the current form, focus events occur in the following order:

1.Enter
2.GotFocus
3.Leave
4.Validating
5.Validated
6.LostFocus

When you change the focus by using the mouse or by calling the Focus method, focus events occur in the following order:

1.Enter
2.GotFocus
3.LostFocus
4.Leave
5.Validating
6.Validated

If the CausesValidation property is set to false, the Validating and Validated events are suppressed.

If the Cancel property of the CancelEventArgs is set to true in the Validating event delegate, all events that would usually occur after the Validating event are suppressed.


I believe that all ContainerControls have a method method for validating their own child controls.


问自己一个问题,为什么您的应用程序必须是MDI应用程序.

然后问问自己,您希望使用MDI子级的方式是否与标准MDI应用程序的方式相对应.

应用程序中的MDI子级旨在显示多个文档或同一文档的多个视图.

每个MDI孩子都应独立于其他任何孩子.如果您的应用程序不能用作MDI应用程序,则不要制作MDI应用程序.而是使用标准表单(并指定所有者,以便它们显示在主表单上方).

一次也只显示一种形式.如果第一个表单是隐藏的(或通过显示拥有的子表单而被禁用),则用户将无法不关闭第二个表单而返回第一个表单.

如果您尝试按照预期的方式工作,那么您会遇到麻烦和很多工作.如果它是MDI应用程序,则必须确保正确处理所有情况,包括(从菜单中)打开新的MDI子项,关闭所有子项等.
Ask yourself the question why your application need to be an MDI application.

Then ask yourself if the way your want to use your MDI child correspond to the way a standard MDI application works.

MDI child in an application are intended to show multiple documents or multiple views of the same document.

Each MDI child should be independant of any other. If your application cannot works as an MDI application, then don''t make a MDI application. Uses standard forms instead (and specify the owner so that they display above the main form).

Also display only one form at a time. If the first form is hidden (or disabled by having an owned child form displayed), then the user won''t be able to go back to the first form without closing the second one.

If you try to works around intended way, then you ask for trouble and lot of work. If it is an MDI application, you will have to ensure that you properly handle all case including opening a new MDI child (from the menu), closing all child and such.


这篇关于防止儿童MDI休假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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