Illishar
Illishar

Reputation: 936

Read .NET Control "Design" properties at runtime

How do you read out the .NET Windows.Forms "Design" properties at runtime? (I assume it must be possible, as Designers etc. are using them.) The "Design" properties are the GenerateMember, Locked and Modifiers.

Eg. I want to read the Modifiers property at runtime. If the control is marked as "public", I'll attach a tooltip to it. Or whatever.

Upvotes: 3

Views: 201

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125292

Locked property is added by ControlDesigner and Modifiers and GenerateMember are added by ModifiersExtenderProvider just at design time.

They are not real properties of control and they are just useful for designer support and the default serializer doesn't generate any code about them and therefor you can not see them at runtime.

For example Locked doesn't have any meaning for runtime.

About knowing if the control has a member and if the member is public or not, you can rely on reflection.

Example

public bool IsMemberGenerated(string name)
{
    var field = this.GetType().GetField(name, System.Reflection.BindingFlags.Public |
        System.Reflection.BindingFlags.NonPublic |
        System.Reflection.BindingFlags.Instance);
    return field != null;
}

Upvotes: 2

Related Questions