How to hide the parent property in UserControl?
-
Hi! i have made a user control with combo box over it. now i want to hide the BorderStyle property of the user control so that end user could not change this property. how can i achieve this functionality?
You need to 'shadow' the BorderStyle property in your control, then set property attributes to hide it from the VS property editor, e.g.
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> \_ Public Shadows Property BorderStyle() As BorderStyle Get Return MyBase.BorderStyle End Get Set(ByVal value As BorderStyle) MyBase.BorderStyle = value End Set End Property
The Browsable attributes hides the property from the VS editor, the DesignerSerializationVisibility atrtibute stop the VS designer generating code for the property in the InitialiseComponent method. You need to use the Shadows keyword in the property def to stop the compiler generating a warning.
"An eye for an eye only ends up making the whole world blind"
-
You need to 'shadow' the BorderStyle property in your control, then set property attributes to hide it from the VS property editor, e.g.
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> \_ Public Shadows Property BorderStyle() As BorderStyle Get Return MyBase.BorderStyle End Get Set(ByVal value As BorderStyle) MyBase.BorderStyle = value End Set End Property
The Browsable attributes hides the property from the VS editor, the DesignerSerializationVisibility atrtibute stop the VS designer generating code for the property in the InitialiseComponent method. You need to use the Shadows keyword in the property def to stop the compiler generating a warning.
"An eye for an eye only ends up making the whole world blind"
-
You need to 'shadow' the BorderStyle property in your control, then set property attributes to hide it from the VS property editor, e.g.
<Browsable(False), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> \_ Public Shadows Property BorderStyle() As BorderStyle Get Return MyBase.BorderStyle End Get Set(ByVal value As BorderStyle) MyBase.BorderStyle = value End Set End Property
The Browsable attributes hides the property from the VS editor, the DesignerSerializationVisibility atrtibute stop the VS designer generating code for the property in the InitialiseComponent method. You need to use the Shadows keyword in the property def to stop the compiler generating a warning.
"An eye for an eye only ends up making the whole world blind"
-
Please tell me one thing. how can i add summary detail for my user control property? the way you can see for anyother property and methods and even for events in objectbrowser.
Hi, use the Description attribute. You may also want to check out the Category and DefaultValue attributes, e.g.
<Description("example property"), DefaultValue(1), Category("Testing")>
All these attributes are in the System.ComponentModel namespace
"An eye for an eye only ends up making the whole world blind"