在设计时隐藏私有的子控件属性 [英] Hide private child control property at design time
问题描述
我有一个带有私有子控件的容器控件.如何在设计时隐藏属性浏览器以使其不显示控件.在设计时,每个控件上还显示了一个锁和一个正方形图标.
I have a container control with some private child control. How to hide the property browser from showing the control at design time. also it shows a lock and a square icon on each of the control at design time.
我尝试设置控件
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Bindable(False)>
<EditorBrowsable(EditorBrowsableState.Never)>
还尝试为子控件设置< DesignTimeVisible(False),ToolboxItem(False)>
.但即使无法编辑,它仍会显示在设计器中.
also tried to set <DesignTimeVisible(False), ToolboxItem(False)>
for the child control. but still shows up in the designer even though it is not editable.
当前,我正在设计时和运行时绘制控件,以加载实际控件.有没有更简单的方法可以做到这一点?
Currently I am painting the control at design time and on runtime loading the real control. is there a simpler way to do this?
推荐答案
选项1-设置GenerateMember = false
In the design mode of the base control, set GenerateMember
property of the child control to false
. This way the derived control wont allow selection of the button.
选项2-使用TypeDescriptor为子控件设置一个新的无效设计器
另一个技巧是在初始化组件之后,在基本控件的构造函数中使用 typeDescriptor.AddAttributes
为子控件设置一个新的不起作用的子控件:
Another trick is setting a new non-working designer for child control using typeDescriptor.AddAttributes
, in the constructor of the base control, after initialize components:
TypeDescriptor.AddAttributes(this.button1, new DesignerAttribute(typeof(object)));
这篇关于在设计时隐藏私有的子控件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!