Serialcoder en Français Serialcoder in English
TEL : +33 (0)9 72 13 15 17

Windows Forms FAQ resources

2. Windows Forms Controls

2.35 How can I have the control designer create the custom editor by calling the constructor with the additional parameters rather than the default constructor?


You can do this by creating the editor yourself rather than allowing TypeDescriptor to do it:


1) Shadow the property you care about in your designer...

     protected override void PreFilterProperties(IDictionaryProperties props)
     {
          PropertyDescriptor basePD = props["MyProperty"];
          props["MyProperty"] = new EditorPropertyDescriptor(basePD);
     }

2) Create a property descriptor that "wraps" the original descriptor

     private class EditorPropertyDescriptor : PropertyDescriptor
     {
          private PropertyDescriptor basePD;
          public EditorPropertyDescriptor(PropertyDescriptor base)
          {
               this.basePD = base;
           }

          // now, for each property and method, just delegate to the base...
          public override TypeConverter Converter
          {
               get { return basePD.Converter; }
          }

          public override bool CanResetValue(object comp)
          {
               return basePD.CanResetValue(comp);
           }
     

          // and finally, implement GetEditor to create your special one...

3) create your editor by hand when it's asked for

          public override object GetEditor(Type editorBaseType)
          {
               if (editorBaseType == typeof(UITypeEditor))
               {
                    return new MyEditor(Param1, param2, param3);
               }
               return basePD.GetEditor(editorBaseType);
          }
     }

(from sburke_online@microsoft..nospam..com on microsoft.public.dotnet.framework.windowsforms)