As has been mentioned, you can't change the property name; how would you code against it, for example? However, if this is for data-binding, you can do some tricks to bend the display name of properties at runtime - for example ICustomTypeDescriptor
/TypeDescriptionProvider
(and a custom PropertyDescriptor
).
Lots of work; it would need to really be worth it...
Another option is a custom attribute:
using System;
using System.ComponentModel;
using System.Windows.Forms;
class MyDisplayNameAttribute : DisplayNameAttribute {
public MyDisplayNameAttribute(string value) : base(value) {}
public override string DisplayName {
get {
return @"/// " + base.DisplayNameValue + @" \\\";
}
}
}
class Foo {
[MyDisplayName("blip")]
public string Bar { get; set; }
[STAThread]
static void Main() {
Application.EnableVisualStyles();
using (Form form = new Form {
Controls = {
new PropertyGrid {
Dock = DockStyle.Fill,
SelectedObject = new Foo { Bar = "abc"}}
}
}) {
Application.Run(form);
}
}
}