Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Set Property Browsable to make false at runtime
 

Set Property Browsable to make false at runtime

Hi Msdn,

I am having one class and their properties Backcolor ,Forecoolor,etc

at runtime depending on one condition i want to make the backcolor property to false and should not be shown to user

THis is code i am having but it is readOnly . How can i make to Browsable atttribute to False.

  Dim property_descriptors As _
        PropertyDescriptorCollection = _
        TypeDescriptor.GetProperties(GetType(cCustomControlProperties))

                            Dim attributes As AttributeCollection = _
          property_descriptors("BackColor").Attributes
                            Dim browsable_attribute As BrowsableAttribute
                            browsable_attribute = _
                                CType(attributes(GetType(BrowsableAttribute)), _
                                    BrowsableAttribute)
----------------------------------------------------------------
browsable_attribute.Browsable = False
----------------------------------------------------------------
End If Next Regards ,




VS
SilverPlate  Monday, May 18, 2009 2:08 PM

Hi SilverPlate,

You can implement a custom type converter for your class to hide or show the BackColor property in the Properties window. The following is a sample:

class MyTypeConverter : TypeConverter
{
public override bool GetPropertiesSupported(ITypeDescriptorContext context)
{
return true;
}
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
{

PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(typeof(cCustomControlProperties),attributes);
if (pdc["conditionPropertyName"].GetValue(value).Equals(false))
{
PropertyDescriptor[] newpdcArray = new PropertyDescriptor[pdc.Count - 1];
int i = 0;
foreach (PropertyDescriptor pd in pdc)
{
if (!pd.Name.Equals("BackColor"))
{
newpdcArray[i++] = pd;
}
}
PropertyDescriptorCollection newpdc = new PropertyDescriptorCollection(newpdcArray);
return newpdc;
}
else
{
return pdc;
}
}
public override bool GetCreateInstanceSupported(ITypeDescriptorContext context)
{
// always force a new instance
return true;
}
public override object CreateInstance(ITypeDescriptorContext context, System.Collections.IDictionary propertyValues)
{
cCustomControlProperties newobj = new cCustomControlProperties();
newobj.Property1 = propertyValues["Property1"] as string;
newobj.Property2 =(bool)propertyValues["Property2"];
....
return newobj;
}
}

Hope this helps.
If you have anything unclear, please feel free to let me know.

Sincerely,
Linda Liu


Please remember to mark the replies as answers if they help and unmark them if they provide no help. end us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
Linda Liu  Tuesday, May 26, 2009 9:44 AM
Hi Linda ,

Thanks For Replying .

Actually i am having a list of controls in multiple Controls selections like Picturebox,Textbox ,Label,LinkLabel etc .

Now i got Picturebox in the Multiple selection of control .

In cCustomProperties Class i am having FORECOLOR ,BACKCOLOR ,FONT ,SIZE , LOCATION
Common Properties
class all the controls to show for multiple controls if selected in the propertygrid.

Case :: 1
If i get the PICTUREBOX in the
List Of Multiple Controls i want to hide the FONT,FORECOLOR,BACKCOLOR Properties and to show only LOCATION,SIZE PROPERTIES .

Case :: 2
For LINKLABEL i am fixing the size of the Linklabel to 7,7 and label text as * .So if i get the linkLabel in the list of Multiple controls i want to hide the SIZE ,FORECOLOR,BACKCOLOR PROPERTIES



Presently i am taking different class for all these conditions and doing Permutations & Combinations . Which is Risky THING TO DO THE THINGS . I want to Stop doing all these non-Sense things .

I want to implement the way in visual studio if Multiple Controls are selected . In the PropertyGrid i get only the properties which are common to all the controls .

Ex :: Consider the label and Picturebox in Multiple Selection. THE FONT PROPETY is hiding . IN THIS WAY DYNAMICALLY .


Regards



VS
SilverPlate  Thursday, May 28, 2009 3:45 PM

You can use google to search for other answers

Custom Search

More Threads

• Custom Control not appearing in ToolBox
• Form Blew Up??!
• Winword version and Browser version ?
• default toolbox tab for usercontrol
• Disable execution in designer time
• Is there a fix for VS2005 crash when viewing infopath/FormControl property?
• DataGridViewComboBox Column DataBinding
• TreeView custom property problem
• VS Closes when I select a certain control.
• Re: designer can't load form. Where is 'more information'?