how do I find out themed WinForms control's theme-based property values? for DevExpress or for WinForms in general
I am dealing with this issue in DevExpress.XtraEditors context, but maybe the answer would also apply to other situations where themes are used for WinForms controls.
Basically, how do I find out what collection of property settings does a themed control have? Is there a way for me to go look at the theme definition? A开发者_如何学编程lso, can I look at these settings dynamically, i.e. from within the app during execution (much like I can print out unthemed Appearance.BackColor during execution)?
I'm not certain what you're looking for, but if you're interested in finding all of a control's (or control Type
's) 'Appearance' properties you can use the TypeDescriptor.GetProperties method. This method returns a PropertyDescriptorCollection from which you can pick out the properties with the CategoryAttribute.Appearance
property.
You can use this method on an instance of the control:
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(myButtonInstance);
Or, on a control Type
:
PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(Button));
But once you get a PropertyDescriptorCollection
you can test for the presence of CategoryAttribute.Appearance
(which means the property appears in the control's 'Appearance' section - assuming Browsable == true) like this:
foreach (PropertyDescriptor property in properties) {
if (property.Attributes.Contains(CategoryAttribute.Appearance)) {
Console.WriteLine("{0} - {1}", property.Name, property.Description);
// Do whatever...
}
}
精彩评论