Windows Develop Bookmark and Share   
 index > Windows Forms Designer > How to hide "greyed" properties in Properties explorer
 

How to hide "greyed" properties in Properties explorer

Hi, All

I have a custom class that inherits fromthe RichTextBox control. When I drag and drop it on a form, in the Property explorer I see all the normal RichTextBox properties, my custom properties and many greyed (Read Only) properties that are not displayed if I drag&drop the actual RichTextBox control on the same form. I know that these are the properties that are either marked as non-browsable or readonly in the RichTextBox control, but how to hide them in Property explorer is the question.

I tried the following attributes to overcome this problem without success.

[Browsable (false)]

[EditorBrowsable (EditorBrowsableState.Never)]

Thank you,

Aleksey
Aleksey Nagoga_  Thursday, September 13, 2007 1:45 PM

ok, I looked at my project again and the model is a bit different, sorry for the little confusion above:

I have a class A that derives from the RichTextBox. If I drag it from the Toolbox to a test form the Properties window does not have any hidden (grey) properties shown, as in your test as well.

Now, in another project, which is the part of the same solution, I have another class (B). That class B derivesfrom the class Amentioned above and in addition it has its own type converter. This is the class that shows grey properties in the Properties window and the problem is probably somewhere in the TypeConverter class.

Here is the source code of the type converter:

public class TypeConverter_B : TypeConverter

{

public TypeConverter_B()

{

}

/// <summary>

/// allows us to display the + symbol near the property name

/// </summary>

/// <param name="context"></param>

/// <returns></returns>

public override bool GetPropertiesSupported(ITypeDescriptorContext context)

{

return true;

}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)

{

return TypeDescriptor.GetProperties(typeof(A));

}

}

I can see now that the problem is most likely with the TypeDescriptor.GetProperties method. It has another overload where I can pass attributes as a filter, and that what's missing I bet.

Thank you.

[EDIT]

ok, the problem is fixed by changing the line

return TypeDescriptor.GetProperties(typeof(A));

to

return TypeDescriptor.GetProperties(typeof(A), new Attribute[] { new BrowsableAttribute(true)});

[/EDIT]

Aleksey Nagoga_  Wednesday, September 19, 2007 1:34 PM

Hi , you can hide this properties by making its modifier to be private or protected .But if your propertymust be public you can set ComponentModel.Browsable to Flase . I tried it & itworked well as following :-

Code Snippet

<ComponentModel.Browsable(False)> _

Public Property TestExecution() As Boolean

Get

....

End Get

Set(ByVal value As Boolean)

.....

End Set

End Property

I hope this will help you .
Pr.Wael  Saturday, September 15, 2007 8:10 AM

Yes, I need the property to be public. This is how I hide AccessibilityObject property for example:

Code Snippet

[DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden)]

[Browsable(false)]

[EditorBrowsable(EditorBrowsableState.Never)]

public new AccessibleObject AccessibilityObject

{

get

{

return base.AccessibilityObject;

}

}

I recompile the solution, even run Clean Solution first before Build Solution, then open my Debug form, which is in the Debug project located in the same solution and drop the control on the form. When I select Clean Solution the control disappears from the Toolbox and when I select Build Solutionthe controlappears there again, so this guaranties that I'm using the newly rebuilt control with the code above, yet when I go to the Properties window of that control I still see the AccessibilityObject in the list. It is disabled (grey), but it is still there.

Aleksey Nagoga_  Monday, September 17, 2007 2:58 PM

The AccessibilityObject property is unbrowsablw by default, I test with the following code andno problem, the property DO NOT show up in the property list in the property view

class myButton : Button
{
public new AccessibleObject AccessibilityObject
{
get
{
return base.AccessibilityObject;
}
}
}

Zhi-Xin Ye  Wednesday, September 19, 2007 10:31 AM

ok, I looked at my project again and the model is a bit different, sorry for the little confusion above:

I have a class A that derives from the RichTextBox. If I drag it from the Toolbox to a test form the Properties window does not have any hidden (grey) properties shown, as in your test as well.

Now, in another project, which is the part of the same solution, I have another class (B). That class B derivesfrom the class Amentioned above and in addition it has its own type converter. This is the class that shows grey properties in the Properties window and the problem is probably somewhere in the TypeConverter class.

Here is the source code of the type converter:

public class TypeConverter_B : TypeConverter

{

public TypeConverter_B()

{

}

/// <summary>

/// allows us to display the + symbol near the property name

/// </summary>

/// <param name="context"></param>

/// <returns></returns>

public override bool GetPropertiesSupported(ITypeDescriptorContext context)

{

return true;

}

public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)

{

return TypeDescriptor.GetProperties(typeof(A));

}

}

I can see now that the problem is most likely with the TypeDescriptor.GetProperties method. It has another overload where I can pass attributes as a filter, and that what's missing I bet.

Thank you.

[EDIT]

ok, the problem is fixed by changing the line

return TypeDescriptor.GetProperties(typeof(A));

to

return TypeDescriptor.GetProperties(typeof(A), new Attribute[] { new BrowsableAttribute(true)});

[/EDIT]

Aleksey Nagoga_  Wednesday, September 19, 2007 1:34 PM

You can use google to search for other answers

Custom Search

More Threads

• Disable mouseDoubleClick on form (WndProc)
• Need help with CodeDomSerializer
• Add design time support to wrapped user controls
• Inherited controls moves
• Exception has been thrown by the target of an invocation. While using DesignerHost
• How to make inplace editor not editable.
• VS 2005 Winform designer Issue
• Designer error
• Error loading string resource?
• Persist Hashtable property