views:

99

answers:

1

I've created a component whose name I'd like to be able to change while editing in the component tray. I've added a Designer action for a name property, but now I'm stuck.

Looking at the property grid, I can see that the name property is parenthesised, indicating that it's not a regular property.

Is this possible?

A: 

Some of the properties are special in the Design Environment and you can only really set them via the Type Descriptor. This may be the case for the name, but it certainly is the case for things like Visible, Locked and Enabled. Perhaps this will give you something to look at for now.

SetHiddenValue(control, "Visible", false);
SetHiddenValue(control, "Locked", true);
SetHiddenValue(control, "Enabled", false);

    /// <summary>
    /// Sets the hidden value - these are held in the type descriptor properties.
    /// </summary>
    /// <param name="control">The control.</param>
    /// <param name="name">The name.</param>
    /// <param name="val">The val.</param>
    private static void SetHiddenValue(Control control, string name, object val)
    {
        PropertyDescriptor descriptor = TypeDescriptor.GetProperties(control)[name];
        if (descriptor != null)
        {
            descriptor.SetValue(control, val);
        }
    }
Markie