Hide private child control property at design time

孤者浪人 提交于 2020-01-14 10:07:57

问题


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.

I tried to set for the control

<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Bindable(False)>
<EditorBrowsable(EditorBrowsableState.Never)>

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:


Option 1 - Set 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.

Option 2 - Using TypeDescriptor set a new non-working designer for the child control

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)));


来源:https://stackoverflow.com/questions/57034662/hide-private-child-control-property-at-design-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!