从splitcontainer上的另一个活动表单输入活动表单上的数据 [英] Input data on active form from another active form on splitcontainer

查看:69
本文介绍了从splitcontainer上的另一个活动表单输入活动表单上的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有4个组件,MDIForm,SplitContainer,Form1,Form2.我将SplitContainer放在MDIForm上,并将Form1和Form2都作为子窗体放在SplitContainer.Panel1上. Form1和Form2都有1个文本框和1个按钮.并且Form1和Form2均处于活动状态(均显示在SplitContainer.Panel1上,未隐藏或关闭).
现在我想使用Form2上Textbox上的值来填充Form1上的Textbox.
请有人帮我.

I have 4 component, MDIForm,SplitContainer,Form1,Form2. I put SplitContainer on MDIForm, and both Form1 and Form2 as childform on SplitContainer.Panel1.
Both Form1 and Form2 has 1 Textbox and 1 button. And both Form1 and Form2 is active (both shown on SplitContainer.Panel1, not hidden or close).
Now i want to fill Textbox on Form1 using value on Textbox on Form2.
Is somebody can help me, please.

推荐答案

不能同时激活两个顶级表单.仅当一个具有MDI客户端并且拥有另一个表单以及MDI子级时,两个表单(并且不超过两个)可以同时处于活动状态.您的描述中肯定有错误.

但是,问题本身与活动状态或MDI无关.这是关于表单协作的流行问题.最健壮的解决方案是在Form类中实现适当的接口,并传递接口引用而不是对Form的整个实例"的引用.请查看我过去的解决方案以获取更多详细信息:如何以两种形式在列表框之间复制所有项目 [在WPF中使用MDI窗口的问题 [ ^ ],
MDIContainer提供错误 [如何最大程度地设置子表单,最小化最后一个子表单 [ ^ ].

另请参见:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [如何在WPF中创建MDI父窗口? [ ^ ].

—SA
No two top-level forms could be active at the same time. Two forms (and not more than two) can be active at the same time, only if one has a MDI client, and it holds another form, and MDI child. Something must be wrong in your description.

However, the question itself has nothing to do with active status or MDI. This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Now, a note about MDI. Who needs MDI, ever? Why torturing yourself and scaring out your users?

Do yourself a great favor: do not use MDI at all. You can do much easier to implement design without it, with much better quality. MDI is highly discouraged even by Microsoft, in fact, Microsoft dropped it out of WPF and will hardly support it. More importantly, you will scare off all your users if you use MDI. Just don''t. I can explain what to do instead.

Please see my past answers where I explain that:
Question on using MDI windows in WPF[^],
MDIContainer giving error[^],
How to set child forms maximized, last childform minimized[^].

See also:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
How to Create MDI Parent Window in WPF?[^].

—SA


这篇关于从splitcontainer上的另一个活动表单输入活动表单上的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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