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 - Moved bynobugzMVP, ModeratorTuesday, May 19, 2009 2:16 AMdesigner q (From:Windows Forms General)
-
| | 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. - Unmarked As Answer bySilverPlate Thursday, May 28, 2009 3:46 PM
- Marked As Answer byLinda LiuMSFT, ModeratorWednesday, May 27, 2009 2:47 AM
-
| | 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- Edited bySilverPlate Thursday, May 28, 2009 3:56 PM
- Edited bySilverPlate Thursday, May 28, 2009 3:57 PM
- Edited bySilverPlate Thursday, May 28, 2009 3:57 PM
-
| | SilverPlate Thursday, May 28, 2009 3:45 PM |
|