如何在自定义用户控件中访问内部控件 [英] How To access inner Control in custom user control

查看:75
本文介绍了如何在自定义用户控件中访问内部控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个标签的自定义控件。

如何为cotrol使用者公开这个标签的所有属性

i creat custom control that have a lable.
how can i expose all property of this lable for cotrol consumer

推荐答案

不要。

如果你这样做,那么你就锁定了自定义控件的设计 - 你不能在不考虑对外界的影响的情况下改变它。



而是向控件添加一个字符串Property,用于获取和设置标签。这样,外界可以更改文本,但是他们不能做任何其他事情,您可以在以后进行任何需要的更改,而不必担心破坏现有代码。
Don't.
If you do, then you lock the design of the custom control - you can't change it without considering the effects on the outside world.

Instead, add a string Property to your control, which gets and sets the label. That way, the outside world can change the text, but they can't do anything else, and you can make any changes you need to at a later date without worrying about breaking existing code.


这篇关于如何在自定义用户控件中访问内部控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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