Windows Develop Bookmark and Share   
 index > Windows Forms General > Hiding properties from the designer
 

Hiding properties from the designer

Really simple question here (in fact, I'm surprised I couldn't find it on my own), but how do you hide properties from the forms designer? I have several properties that are accessors to the properties of contained objects or the objects themselves, but they don't get instantiated until after OnHandleCreated() is called, so I often get null exceptions from the designer.

On that same note, is it possible to hide inherited properties? For instance, I have no need for Control.BackColor.

Thanks in advance!

Luke

Luke DeStevens  Sunday, May 18, 2008 5:50 PM
Use the [Browsable(false)] attribute. That won't solve the NullReferenceException, you'll need to add the code required to create the handle or avoid touching the reference. By the time the properties are editable in the Properties window, the handle will be created.

Override the BackColor property so you can apply the attribute and hide it. For example:

using System;
using System.ComponentModel;
using System.Windows.Forms;

public class MyPanel : Panel {
[Browsable(false)]
public override System.Drawing.Color BackColor {
get { return base.BackColor; }
set { base.BackColor = value; }
}
}
nobugz  Sunday, May 18, 2008 6:08 PM
Use the [EditorBrowsable(EditorBrowsableState.Never)] attribute.
nobugz  Sunday, May 18, 2008 7:07 PM
Use the [Browsable(false)] attribute. That won't solve the NullReferenceException, you'll need to add the code required to create the handle or avoid touching the reference. By the time the properties are editable in the Properties window, the handle will be created.

Override the BackColor property so you can apply the attribute and hide it. For example:

using System;
using System.ComponentModel;
using System.Windows.Forms;

public class MyPanel : Panel {
[Browsable(false)]
public override System.Drawing.Color BackColor {
get { return base.BackColor; }
set { base.BackColor = value; }
}
}
nobugz  Sunday, May 18, 2008 6:08 PM

Thanks, nobugz!

Luke DeStevens  Sunday, May 18, 2008 6:10 PM
Is there a way to hide properties, events, and methods from intellisense? That's more what I wanted to do with useless inherited members such as BackColor.

Luke DeStevens  Sunday, May 18, 2008 6:49 PM
Use the [EditorBrowsable(EditorBrowsableState.Never)] attribute.
nobugz  Sunday, May 18, 2008 7:07 PM

You can use google to search for other answers

Custom Search

More Threads

• Want to merge owc context with my context menu
• Dynamic event handler for dynamic button
• Users
• Newbie: usercontrol load question
• Should be simple: frm1 Save As... frm2, but leave frm1 "as is"
• Make an Image Colour transparent.
• DateTime Picker null value
• How to find out wether given toolstripitem is on toolstrip(non overflow part of toolstrip) or in the overflow part of toolstrip?
• Help dealing with nulls
• Working with multiple forms