Is it possible to create a custom management property that can only be configured at design time?

Possible duplicate:
Can a C # control have only a design-time property?

I want to create a custom management property that can only be set at design time, is this possible?

0
source share
1 answer

Yes ... In your class, create a personal field to determine if your property was originally "set" or not. Then you have your standard getter and setter. However, in the installer, use the license manager to determine what mode you are working in ... designtime vs runtime. Then check. Always allow if in Design-Time, OR if the field is not already set. After that, set the flag as set. This will be needed because when creating an instance of the form designer of controls, it must be installed at least ONE from the code .Designer.cs, but after that ignore any attempts to change it - by setting a flag.

    private Boolean IsCreated = false;

    private String myVar1;
    public String MyVar1
    {
       get { return myVar1; }
       set {
              if (LicenseManager.UsageMode ==  LicenseUsageMode.Designtime 
                    || !IsCreated)
              {
                  myVar1 = value;
                  IsCreated = true;
              }
    }

, , , IsCreated , , . , reset ( ) ,

+2

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


All Articles