Tech Off Thread

4 posts

How do you hide properties?

Back to Forum: Tech Off
  • User profile image
    sysrpl

    When using SWF (System.Windows.Forms), how can I remove a property of a control?

     

    I wrote my own progress control which does not make sense to recieve input focus. As a result, I do not want the tabstop property exposed to others, but this property is public in SWF.Control.

     

    I noticed SWF.Label descends from control, yet it doesn't show a tabstop property. Looking at SWF.Label with reflector I see nothing supressing the tabstop property. How is this done (SWF.Label removing access to its TabStop property)?

     

    Here is the listing for SWF.Label from reflector:

     

    http://pastebin.com/m17e41790

  • User profile image
    ktr

    using System.Windows.Forms; using System.ComponentModel; namespace Test2 { class ProgressBar2 : ProgressBar { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
     public new bool TabStop { get { return ((Control)this).TabStop; } set { ((Control)this).TabStop = value; } } } } 

  • User profile image
    ktr

    ktr said:

    using System.Windows.Forms; using System.ComponentModel; namespace Test2 { class ProgressBar2 : ProgressBar { [Browsable(false)] [EditorBrowsable(EditorBrowsableState.Never)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
     public new bool TabStop { get { return ((Control)this).TabStop; } set { ((Control)this).TabStop = value; } } } } 

    Also, this won't hide the property from intellisense unless the project you are working on lives in a different DLL from the control.  You also can't have the project that the control lives in open in the same VS instance, otherwise intellisense will pick it up.

  • User profile image
    sysrpl

    ktr said:
    ktr said:
    *snip*

    Also, this won't hide the property from intellisense unless the project you are working on lives in a different DLL from the control.  You also can't have the project that the control lives in open in the same VS instance, otherwise intellisense will pick it up.

    Well the control is in a different assembly, but the assembly is in my solution as a separate cs project. And even though it does then seem to be a different assembly, using your code the property still shows up in intellisense (Label.TabStop doesn't show in intellisense), although it is hidden from the property grid.

     

    Why does my reflector listing for Label not show this information?

     

    *Update*

     

    I started a new project and added my control assembly to the reference. In the code editor when I am working with a variable of my control type (which uses your code above) TabStop still shows in the intellisense list. What's up with that? As I said, Label hides it from the intellisense list.

     

    *Update 2*

     

    Nevermind, I got it. TY

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.