Hide custom control properties

Sani Love 160 Reputation points
2023-12-27T01:19:50.6266667+00:00

Hello,

I've created a custom control which Inherits a Panel mainly, and I add some controls inside it.

The problem is that I need to hide the most properties of the panel, either set myself or leave as default!

So in my Designer.vb how can I handle it and hide existing properties?

Thanks :)

  • Update: Found 2 solutions, both work, which one is recommended to use?

<Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> Public Overloads Property TabStop As Boolean

vs

<Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> Public Overloads Property TabStop As Boolean

And when hiding it, how to set it internally?

Developer technologies VB
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Jiachen Li-MSFT 34,221 Reputation points Microsoft External Staff
    2023-12-27T06:25:04.6+00:00

    Hi @Sani Love ,

    Both solutions you mentioned are valid, but they serve different purposes:

    1. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> This combination of attributes (Browsable, EditorBrowsable, and DesignerSerializationVisibility) hides the property in different contexts: Browsable(False): Hides the property from the Property Grid in the Visual Studio designer. EditorBrowsable(EditorBrowsableState.Never): Hides the property from IntelliSense and code completion. DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden): Prevents the property from being serialized into the designer code.
    2. <Browsable(False), EditorBrowsable(EditorBrowsableState.Never)> This combination of attributes hides the property from the Property Grid and from IntelliSense, but it doesn't prevent it from being serialized into the designer code.

    In your case, if you want to completely hide the property from being shown in the Property Grid and prevent its serialization into the designer code, you should use the first combination with all three attributes.

    Within the control's methods or constructor, you can set the properties just like any other property, using Me.MyProperty = False (or whichever value you want to set).

    Best Regards.

    Jiachen Li


    If the answer is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.