Hi,
i'm using the Visual Studio 2oo5 IDE with the 2.0 frameworkand i have a custom component class deriving from System.ComponentModel.Component with a ComponentDocumentDesigner class linked via [DesignerAttribute(...)]. I just want to use the 'Properties' form of the IDE in the design mode. So my component class is not derived from a component which implements a form designer just non-visual components can be placedon the component.The component class works fine when adding to other components or using it as a parent for other components. The component class has a myIcon property of type System.Drawing.Image. What i want is that a developer is able to set the image property from the project resources at design time. All changes to my custom componentis then serialized as code in the IntializeComponents() function which should at run time set the myIcon property. Here's a simplifiedexample of such a custom component:
Code Snippet
public partial class myComponent : Component
{
Image _ic;
[DefaultValue(null)]
public Image myIcon
{
get { return _ic; }
set { _ic = value;}
}
}
Now when i open my component in the designer and click the ellipsis (...) button of the myIcon property the IDE just opens up the file dialog. The problem with the file dialog is thattheCodeDOM serializes this image by putting it into the resx file of the component instead of the project resources. The serialized code when using the file dialog looks like:
Code Snippet
//
// myComponent
//
resources.ApplyResources(this.myComponent, "myComponent");
myComponent.myIcon = ((System.Drawing.Image)(resources.GetObject("myComponent.myIcon")));
but what i want is that the serialized code for the image property should come from the project resources like the form designer does that for example on a toolstrip control:
Code Snippet
//
// myToolStripButton
//
resources.ApplyResources(this.myToolStripButton, "myToolStripButton");
this.myToolStripButton.Image = global::My.Project.Properties.Resources.myIcon;
As you can see the CodeDOM serializer uses simply a property from the StronglyTypedResourceBuilder instead of calling the resources.GetObject() function and that's exactly what i want. For that the serializer must know that there's such an image in the project resources.
Now the strange thing is when i freshly start the IDE and open my component in design mode then i get a file dialog and my image gets serialized into the components resource and the TypeConverter ofthe myIcon property is a simple ImageConverter classbut when i open a form designer ofsome otherform component in the same solution and go back to themyComponent and then click the ellipsis (...) button of themyIcon property i get the Select Resource dialog so i guess when the form designer loads it does some kind of initialization because after that the default converter of any Image propertyis changed toMicrosoft.VisualStudio.Windows.Forms.ResourceConverter<System.Drawing.ImageConverter>which i guess creates the link between the project resources and the type converter. That triggers the IDE to use that Select Resource dialog. According to this blogit's not possible to force the IDE to use the Select Resource dialog via UITypeEditor class and [EditorAttribute(...)]as that dialog is not available as a public class.
Is there anysimpleway to force the serializer to retrieve my images from the global assembly project resource?
I assume that the form designer can't do more than providing some kind of component service which triggers the creation of thatResourceConverter<System.Drawing.ImageConverter> thing or do i probably need to derive from a special designer class which provides that functionality?
What does the form designer do to get that Select Resource dialog in design mode?
Any help is appreciated.