窗口申请表问题 [英] window application form question

查看:114
本文介绍了窗口申请表问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种形式form1和form2
form1是其父级,而form2是其mdi子级.
我在form2上有一个文本框
我可以在表单1上访问文本框值吗?

I have two forms form1 and form2
form1 is the parent and form2 is its mdi child.
i have a textbox on form2
Can i access textbox value on form one ?

推荐答案

如果Form1是MDIparent,则可以遍历MdiChildren属性.像这样的东西:
If the Form1 is the MDIparent, you can loop through the MdiChildren property. Something like:
foreach (Form mdiChild in this.MdiChildren) {
   if (mdiChild is Form2) {
      // some code here, for example: ((Form2)mdiChild).GetTextBoxText()
   }
}


我不建议直接从子窗体中获取文本框的值(即使可能).而是在Form2中定义一个方法,然后从前面的代码示例中调用该方法.在此方法中,从文本框中获取数据,如果需要,可以对其进行修改,然后将其返回.该方法可以很简单:


I wouldn''t advice to directly get the value of a text box from the child form (even though it''s possible). Instead define a method in Form2 and call that method from the previous code example. In this method get the data from the text box, possibly modify it if needed and then return it. The method could be simply:

public string GetTextBoxText() {
   return this.textbox2.Text;
}


你们将用MDI折磨自己并吓customers客户多久?这是邪恶的.

请参阅:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages [在WPF中使用MDI窗口的问题 [ ^ ],
提供错误的MDIContainer [
How much longer you guys are going to torture yourself and scare off your customers with MDI? This is evil.

Please see:
http://en.wikipedia.org/wiki/Multiple_document_interface#Disadvantages[^],
Question on using MDI windows in WPF[^],
MDIContainer giving error[^].

—SA


这篇关于窗口申请表问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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