Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / Design Time / September 2005

Tip: Looking for answers? Try searching our database.

ComponentDesigner and ICustomTypeDescriptor conflict

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Thierry - 31 Aug 2005 19:50 GMT
When a component implements ICustomTypeDescriptor, its component
designer is ignored by the IDE. Just remove the ICustomTypeDescriptor
implementation in the above sample makes the component designer works
again.

I tried several implementation of ICustomTypeDescriptor without
success. Is it incompatible with ComponentDesigner?

Code Sample:

  internal class MyDesigner : ComponentDesigner
    {
   public override System.ComponentModel.Design.DesignerVerbCollection
Verbs
   {
     get
     {
       return new DesignerVerbCollection( new DesignerVerb[] { new
DesignerVerb("Example Designer Verb Command", new
EventHandler(this.onVerb)) } );
     }
   }

   private void onVerb(object sender, EventArgs e)
   {
     MessageBox.Show("The event handler for the Example Designer Verb
Command was invoked.");
   }
 }

[Designer(typeof(MyDesigner))]
 public class MyComponent : IComponent, ICustomTypeDescriptor
 {
   // IComponent and IDisposable implementation removed

   #region ICustomTypeDescriptor Members

   TypeConverter ICustomTypeDescriptor.GetConverter()
   {
     return null;
   }

   EventDescriptorCollection
ICustomTypeDescriptor.GetEvents(Attribute[] attributes)
   {
     return EventDescriptorCollection.Empty;
   }

   EventDescriptorCollection ICustomTypeDescriptor.GetEvents()
   {
     return EventDescriptorCollection.Empty;
   }

   string ICustomTypeDescriptor.GetComponentName()
   {
     return "MyComponent";
   }

   object ICustomTypeDescriptor.GetPropertyOwner(PropertyDescriptor
pd)
   {
     return this;
   }

   AttributeCollection ICustomTypeDescriptor.GetAttributes()
   {
//      if( site != null && site.DesignMode )
//      {
//        object[] attributes =
this.GetType().GetCustomAttributes(true);
//        Attribute[] cattributes = attributes as Attribute[];
//        if( cattributes != null)
//          return new AttributeCollection(cattributes);
//      }
//
     return AttributeCollection.Empty;
   }

   PropertyDescriptorCollection
ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
   {
     return (this as ICustomTypeDescriptor).GetProperties();
   }

   PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties()
   {
//      if( site != null && site.DesignMode )
//        return TypeDescriptor.GetProperties( this, true );
//
     return TypeDescriptor.GetProperties(typeof(DateTime));
   }

   object ICustomTypeDescriptor.GetEditor(Type editorBaseType)
   {
     return null;
   }

   PropertyDescriptor ICustomTypeDescriptor.GetDefaultProperty()
   {
     return null;
   }

   EventDescriptor ICustomTypeDescriptor.GetDefaultEvent()
   {
     return null;
   }

   string ICustomTypeDescriptor.GetClassName()
   {
     return "MyComponent";
   }

   #endregion

 }
Thierry - 01 Sep 2005 20:55 GMT
The following implementation of ICustomTypeDescriptor fix the problem:

   AttributeCollection ICustomTypeDescriptor.GetAttributes()
   {
     if( site != null && site.DesignMode )
     {
       object[] attributes = this.GetType().GetCustomAttributes(true);
       Attribute[] cattributes = new Attribute[ attributes.Length ];
       attributes.CopyTo( cattributes, 0);
       return new AttributeCollection(cattributes);
     }

     return AttributeCollection.Empty;
   }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.