MDI父母和子女表格 [英] MDI Parent and Child Form
问题描述
我有一个表单,我设置为IsMdiParent = true现在我想在父表单按钮单击事件上打开子表单然后子表单有一个文本框和一个按钮.....现在问题是我可以在子表单按钮上单击event得到父表单中文本框的值。我可以这样做吗?
I have one form that i set to the IsMdiParent=true now i want to open the child form on parent form button click event then the child form having one textbox and one button.....now the issue is i can''t get the value of the textbox in the parent form on child form button click event.how can i do this?
推荐答案
尝试这样,
Hi,
try like this,
TextBox txt = (TextBox)childForm1.ParentForm.Controls["txtbox1"];
// txtbox1 ID or name of textbox
// childForm1 is the object of the child form
if(txt !=null)
{
MessageBox.Show(txt.Text.Trim());
}
希望它有所帮助。
hope it helps.
也许这是好方法:
以子格式创建属性作为父级;
maybe this is good way :
make a property in child form as parent;
private ParentForm parent;
public ParentForm Parent
{
get{return parent;}
set{parent=value}
}
你有父表格对象作为你的孩子表格的成员这个属性。
然后使用这个父母形式的代码:
well you have parent form object as a member of your child form whith this property.
then use this code in parent form:
ChildForm child=new ChildForm();
child.Parent=this;
child.Show();
这样,您可以访问子表单中的父表单成员! />
希望有帮助!
with this , you have access to parent form members in your child form!
hope help !
这篇关于MDI父母和子女表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!