Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Can sub-properties be hidden from the property grid?
 

Can sub-properties be hidden from the property grid?

I have a component that displays its properties in a property grid to the user. I am able to add custom properties, remove standard properties, etc. However, I want the user to be able to select the font used for the control. But, I only want them to be able to select the font name and size...none of the other stuff that is contained within the font. Is there a way to hide the other sub-properties?
bdbull  Thursday, January 24, 2008 10:34 PM

Hi bdbull,

Based on my understanding, you want to hide the sub properties of Font in the PropertyGrid for your component, right? If so, you should custom a TypeConvert for the Font of your component. Try something like the following. It helps you hide the sub properties.

Code Snippet

public partial class MyControl : UserControl

{

public MyControl()

{

InitializeComponent();

}

[TypeConverter(typeof(MyFontConvert))]

public override Font Font

{

get { return base.Font; }

set { base.Font = value; }

}

}

class MyFontConvert : FontConverter

{

public override bool GetPropertiesSupported(ITypeDescriptorContext context)

{

return false;

}

}

If you want the use can only edit the Font name and size, you need to custom an Editor for the Font. Check the following thread for a sample about how to custom an Editor.

· http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2199489&SiteID=1

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Tuesday, January 29, 2008 11:27 AM

Hi bdbull,

Based on my understanding, you want to hide the sub properties of Font in the PropertyGrid for your component, right? If so, you should custom a TypeConvert for the Font of your component. Try something like the following. It helps you hide the sub properties.

Code Snippet

public partial class MyControl : UserControl

{

public MyControl()

{

InitializeComponent();

}

[TypeConverter(typeof(MyFontConvert))]

public override Font Font

{

get { return base.Font; }

set { base.Font = value; }

}

}

class MyFontConvert : FontConverter

{

public override bool GetPropertiesSupported(ITypeDescriptorContext context)

{

return false;

}

}

If you want the use can only edit the Font name and size, you need to custom an Editor for the Font. Check the following thread for a sample about how to custom an Editor.

· http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2199489&SiteID=1

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Tuesday, January 29, 2008 11:27 AM

You can use google to search for other answers

Custom Search

More Threads

• ToolboxBitmapAttribute doesn't work
• Code Definition Window
• drop down menu in DataGridView
• Vista-like Progressbar
• webBrowser font resize
• Retrieving the ExtenderProvider from within the EditValue method of a UITypeEditor
• Operation is not valid due to the current state of the object.
• scrollable form disturbs controls location when added at run time
• How to make form movable but prevent maximize
• ArcSWAT