propertygrid

How to refresh localized attributes in PropertyGrid

余生颓废 提交于 2019-12-07 16:29:08
问题 I have problem with my localized attributes such as: public class LocalizedDisplayNameAttribute : DisplayNameAttribute { public LocalizedDisplayNameAttribute(string resourceId) : base(GetMessageFromResource(resourceId)) { } private static string GetMessageFromResource(string resourceId) { var propertyInfo = typeof(Lockit).GetProperty(resourceId, BindingFlags.Static | BindingFlags.Public); return (string)propertyInfo.GetValue(null, null); } } When I'm using properties with this attribute it's

PropertyGrid with Custom PropertyDescriptor

巧了我就是萌 提交于 2019-12-07 07:14:47
问题 I've been struggling quite a bit to get custom PropertyDescriptors to work the way I want with a PropertyGrid. The premise: I have a class called "Animal" which contains the properties Age , Type , Location , and Name . I have another class called "AnimalGroup" which contains a List<Animal> where animals are stored. The class member that contains this list is called Members . In the UI of the program, a PropertyGrid form element will list off the Animals in the AnimalGroup that is assigned to

Passing objects to a UITypeEditor

為{幸葍}努か 提交于 2019-12-07 05:55:40
问题 I am currently hoping to use a PropertyGrid to allow users to edit some of my classes, however I've hit a wall with passing objects to the UITypeEditor(s) they use. When the user presses the drop down I want to show a listbox of already loaded textures to choose from, if they want to use a texture the application hasn't loaded yet they can click a button to choose one from a file dialog. In case I make no sense here a mock of the form: . My problem: To fill the listbox I need access to the

Change the foreground color of read-only properties in a propertygrid

最后都变了- 提交于 2019-12-06 15:45:52
I'm using a WinForms property grid to display the properties of an object. However, most of the properties are read only and thus show up as grey rather then black. Is there a way to customize the colors that are used? I'd like the disabled properties to be a bit easier to read. BTW: I think the answer to this question might be related to what I'm trying to do. But I'm not sure exactly how I can access ControlPaint.DrawStringDisabled . Matt B Unfortunately, there's no built-in way to change the colour. As with a lot of the standard .NET controls, they're merely wrapped versions of their COM

Custom ColorEditor does not work properly on Color struct

旧街凉风 提交于 2019-12-06 15:09:08
I asked here how to use custom color dialog in property grid for Color struct: Using custom color picker dialog in PropertyGrid From that link you can see code of MyColorEditor class if needed. Now i can use custom color dialog but only if i use my own struct which is RGBA in that example. If i use this custom type editor on color struct it looks like this in property grid: But if i use RGBA struct which i created, it looks properly: Problem happens because UITypeEditorEditStyle.Modal not applying with GetEditStyle() i think. Using Color struct can be better than using my custom color struct

How to set DefaultValueAttribute of the PropertyGrid dynamically or at runtime?

不羁的心 提交于 2019-12-06 11:12:12
I am defining a custom class to be used with the PropertyGrid control. Say, one of the properties is defined as such: [CategoryAttribute("Section Name"), DefaultValueAttribute("Default value"), DescriptionAttribute("My property description")] public string MyPropertyName { get { return _MyPropertyName; } set { _MyPropertyName = value; } } private string _MyPropertyName; As you see DefaultValueAttribute defines a default value for the property. Such default value is used in two cases: If this property value is changed from the default one the PropertyGrid control will display it in bold, and If

WinForms designer properties of different derived types

若如初见. 提交于 2019-12-06 10:51:55
问题 Say I have a particular type that I want to make available to the Windows Forms designer... public class Style { public CustomBrush Brush { get; set; } } And CustomBrush is implemented like so... public abstract CustomBrush { ... } public SolidCustomBrush : CustomBrush { ... } public GradientCustomBrush : CustomBrush { ... } Is there a way at design time that I can choose from any of the types derived from CustomBrush , instantiate an instance of the selected type, and modify it via the

How to customize names in “Add” button dropdown in the PropertyGrid custom collection editor

╄→гoц情女王★ 提交于 2019-12-06 05:35:14
I'm using PropertyGrid to edit a collection. An object with the collection is defined as following: class ObjWithCollection { [Editor(typeof(MyCustomCollectionEditor),typeof(UITypeEditor))] public List<ItemBase> collection { get; set; } = new List<ItemBase>();//ItemBase is abstract } The collection contains the objects of two types, derived from ItemBase class: Item1 and Item2 . These classes defined as following: public abstract class ItemBase { public string Name { get; set; } public ItemBase() { } public ItemBase(string name) { Name = name; } } public class Item1:ItemBase { public Item1()

How to get a PropertyGrid's cell value (c#)?

耗尽温柔 提交于 2019-12-06 03:45:54
How can I get property grid items and item's value in c# ? for example : Name : Ali LastName : Ahmadi (Name and LastName are 2 properties of propertygrid) PropertyGrid is just a view over the component-model representation of an object. Rather than look at the grid, I would say: look at the component-model, for example: var props = TypeDescriptor.GetProperties(obj); foreach(var prop in props) { string name = prop.DisplayName; if(string.IsNullOrEmpty(name)) name = prop.Name; Console.WriteLine("{0}: {1}", name, prop.GetValue(obj)); } Ali Ahmadi Correct answer is : private void button1_Click

How to refresh localized attributes in PropertyGrid

本小妞迷上赌 提交于 2019-12-06 00:23:16
I have problem with my localized attributes such as: public class LocalizedDisplayNameAttribute : DisplayNameAttribute { public LocalizedDisplayNameAttribute(string resourceId) : base(GetMessageFromResource(resourceId)) { } private static string GetMessageFromResource(string resourceId) { var propertyInfo = typeof(Lockit).GetProperty(resourceId, BindingFlags.Static | BindingFlags.Public); return (string)propertyInfo.GetValue(null, null); } } When I'm using properties with this attribute it's localized in PropertyGrid, but when I change the current CultureInfo it doesn't refresh, even if I