儿童父母问题 [英] Child -parent issue

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

问题描述

大家好...
我需要MDI父母的帮助.
我可以有一个父母和5个mdi子女吗?
我知道如何从mdichild访问父级.
但是我可以从父级访问子级中的控件吗?
thx All.

Hi All...
I need some help in mdi parents .
will i have a parent and 5 mdi childs.
i know how to access the parent from mdichild.
but can i access the controls in child from parent and how ??
thx All.

推荐答案

是的-将它们公开,而不是受保护/私有.
Yeah - make them public instead of protected/private.


父母的MdiChildren属性为您提供一个Form的数组.您需要将所需的基Form从集合强制转换为您的孩子的派生类.一旦有了它,就可以访问在子级中创建的公共属性或方法.

不要公开控件本身!
The Parent''s MdiChildren property gives you an array of Forms. You need to cast the base Form that you want from the collection to the derived class that is your child. Once you have that, you can access public properties or methods you create in the child.

Don''t make the control''s themselves public!


正如约翰所说,您需要公开对控件的访问.我仔细地说了访问权限,而不是公开公开控件,因为您要公开表单的内部工作原理,这是面向对象的宗旨之一.也就是说,您应该使用封装.

例如,假设您想控制对复选框中选中属性的访问,则将其包装在一个属性中,然后调用它.因此,您将拥有一个如下所示的属性:
As John said you need to make the access to the controls public. I carefully said access rather than making the controls public themselves because you are exposing the inner workings of the form, which is one of the tenets of object orientation; namely you should use encapsulation.

For instance, suppose you want to control the access to the checked property on a checkbox, you would wrap it up in a property and you''d call that instead. So you''d have a property that looks like this:
public bool HasTakenWarranty
{
  get { return chkWarranty.Checked; }
  set { chkWarranty.Checked = value; }
}

如您所见,您已经包装了对选中状态的访问权限,因此您不必提供对所有属性的公共访问权限控制.这也意味着您可以提供一种属性/方法,该属性/方法一次可以作用于多个控件.

As you can see from this, you have wrapped up the access to the checked state so that you don''t have to provide public access to all the properties on the control. This also means that you can provide one property/method that acts on more than control at a time.


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

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