访问从childform parentform控制 [英] accessing controls on parentform from childform
本文介绍了访问从childform parentform控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从childform上parentform改变文本框的文本。
我设置文本框
I want to change text in textbox on parentform from childform. I set textbox
改性剂=公共
I有额外的写在parentform功能
modifiers= public i have extra written a function in parentform
public TextBox txtbox
{
get
{
return mybox;
}
set
{
mybox= value;
}
}
在写作
这个孩子的形式。 ParentForm。 (看不到myBox上)。
我缺少的是什么。
的问候,
in child form on writing this.ParentForm. ( can't see mybox). what i am missing. regards,
推荐答案
由于 ParentForm
将返回一个表格
,而不是的您的形式,你需要转换它之前,你可以访问任何自定义属性:
Since ParentForm
will return a Form
and not your form, you need to cast it before you can access any of your custom properties:
((MyForm)this.ParentForm).textbox = "new text!";
此外,您正在设置的全部的控制,而不仅仅是文字。
Additionally, you are setting the whole control, not just the text.
试试这个,揭露文本属性只:
Try this, to expose the text property only:
public string txtbox
{
get
{
return mybox.Text;
}
set
{
mybox.Text = value;
}
}
这篇关于访问从childform parentform控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文