PropertyGrid - is it customizable?

I have a project in which we need to represent some graphical objects in usercontrol in WYSIWYG. It is also required to change the properties of each object (color, location, etc.).

alt text http://lh6.ggpht.com/_1TPOP7DzY1E/TBHz8PW8MQI/AAAAAAAADPE/kzAbKKsEkmU/s144/Untitled.gif

I am confused between using PropertyGrid ('direct' edit edit) and custom forms in DoubleClick ('indirect' editing).

PropertyGrid is very good, but must meet some criteria:

  • Only selected properties are displayed (for example, if I have a TextRectangle only wants to display Text and location);
  • The names of the objects must be customizable and internalizable (for example, the TextRectangle Text property should be "Company Name" or "Company Name").

Now, perhaps, I think the answer may be yes, but is it wise to use it if we do not have much time. What can be done faster, custom forms or property bar?

EDIT:
Most of the examples I saw on the Internet were with fully customizable objects . Witch properties can be easily controlled. The problem is that I would also display ready-made .NET Framework objects that I cannot control, such as TextBoxes, Label, RectangleShape or OvalShape (VB.Powerpacks)

Is it possible to hide all properties and specify only a few of them that should be present?

+3
3

PropertyGrid .

TypeConverter, / PropertyGrid. "" . /. Typeconverter .

UITypeEditor , (, , colorpicker,... )

DisplayName , . , . , .

(, Rune Grimstad ), , [Browsable (false)].

DefaultValue, , DefaultValue, . , .

, TextBox . , ( TypeConverter) . -, :

class BaseWrapper<T> {
    public BaseWrapper(T tb) {
        this.Wrapped = tb;
    }

    [Browsable(false)]
    public T Wrapped { get; set; }

    public object GetMember(string name) {
        var prop = this.Wrapped.GetType().GetProperty(name);
            return prop.GetValue(this.Wrapped, null);
    }

    public void SetMember(string name, object value) {
        var prop = this.Wrapped.GetType().GetProperty(name);
        prop.SetValue(this.Wrapped, value, null);
    }
}

class BaseConverter<T> : TypeConverter {
    protected class pd : SimplePropertyDescriptor {
        public pd(string displayName, string name) : base(typeof(BaseWrapper<T>), displayName, typeof(string)) {
            this.PropName = name;

        }
        public string PropName { get; set; }

        public override object GetValue(object component) {
            var wrapper = (BaseWrapper<T>)component;
            return wrapper.GetMember(this.PropName);
        }
        public override void SetValue(object component, object value) {
            var wrapper = (BaseWrapper<T>)component;
            wrapper.SetMember(this.PropName, value);
        }
    }
    public override bool GetPropertiesSupported(ITypeDescriptorContext context) {
        return true;
    }
}

[TypeConverter(typeof(TextBoxConverter))]
class TextboxWrapper : BaseWrapper<TextBox> {
    public TextboxWrapper(TextBox t) : base(t) { }
}

class TextBoxConverter : BaseConverter<TextBox> {
    public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) {
        return new PropertyDescriptorCollection(new PropertyDescriptor[] {
            new pd(" ", "Text")
        });
    }
}

, :

this.propertyGrid1.SelectedObject = new TextboxWrapper(this.textBox1);

pd ( , ), .

+2

You can see this article in CodeProject. It uses the generic PropertyBag to contain any properties that you want to pull out of its object (s), and gives the PropertyBag to display the PropertyGrid.

+1
source

Source: https://habr.com/ru/post/1749533/


All Articles