Windows Develop Bookmark and Share   
 index > Windows Forms Designer > "Select Resource" Dialog not appearing when in Design Mode.
 

"Select Resource" Dialog not appearing when in Design Mode.

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.

a3ronco  Friday, April 04, 2008 4:35 PM

Hi 3ronco,

I can reproduce this issue with your steps and I have to admit that the behavior is less desirable. To feedback this issue in a formal way, could you please go to our Connect portal site and submit it?

·https://connect.microsoft.com/VisualStudio/

In your feedback, you can quote the URL to this thread, so that the whole conversation can be available. Every feedback submitted will be evaluated carefully by our engineers. They will let you know their comments further through that portal. It would be great if you can also paste the link to the submitted feedback here, so that other community members can see it as well.

Thanks.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, April 11, 2008 2:55 AM

Hi 3ronco,

I performed a test according to your description, and I found that if I use the Icon as the type the property, I got the FileOpenDialog, but if I use the Image as the type of the property, I get the 'Select Resouce' dialog. And here is my testing code:

Code Snippet

public class myComponent : Component

{

Image _ic;

[DefaultValue(null)]

public Image MyImage

{

get { return _ic; }

set { _ic = value; }

}

Icon icon;

public Icon Icon

{

get { return icon; }

set { icon = value; }

}

}

As Raghavendra Prabhu already pointed out in his blog, there is no way to reference the Select Resource dialog as a UITypeEditor for your custom property, since it is implemented in a VS package, and not in the framework. It will automatically show up for properties of type Image, and is designed to be used only for that type.

Hope this helps.
Best regards.
Rong-Chun Zhang

Rong-Chun Zhang  Thursday, April 10, 2008 4:54 AM

Hi Rong-Chun,

thanks for taking the time to investigate into this topic.

Hmmm...then we have a different behavior here. I'm already using a property of type System.Drawing.Image but to be absolutely sure i've prepared a little example project to be able to reproduce the problem. Could you please take the time and check out my example so that i know i don't have to dig into this any longer. Here is what i did:

1. Open WindowsApplication1.sln Solution
2. 2xClick NonVisualComponent.cs
3. Drag myCustomComponent from the ToolBox into NonVisualComponent.cs [Design]
4. Click myCustomComponent1 in the designer surface
5. Click the ellipsis [...] of the myImage property in the properties tab
6. *** File Dialog appears *** >> cancel
7. 2xClick VisualComponent.cs
8. Drag myCustomComponent from the ToolBox into VisualComponent.cs [Design]
9. Click myCustomComponent1 in the designer surface
10. Click the ellipsis [...] of the myImage property in the properties tab
11. *** Select Resource appears *** >> cancel
12. Switch to NonVisualComponent.cs [Design]
13. Click myCustomComponent1 in the designer surface
14. Click the ellipsis [...] of the myImage property in the properties tab
15. *** Select Resource appears ***

As far as i can tell the project resources doesn't get linked to the TypeConverter when you use a non-visual component as a parent. After using a visual component as a parent like the Form designerthe Select Resource dialog appears as expected and what's strange is that once a visual component was started the same dialog also appears in any non-visual component.

Regards

3ronco

a3ronco  Thursday, April 10, 2008 11:11 AM

Hi 3ronco,

I can reproduce this issue with your steps and I have to admit that the behavior is less desirable. To feedback this issue in a formal way, could you please go to our Connect portal site and submit it?

·https://connect.microsoft.com/VisualStudio/

In your feedback, you can quote the URL to this thread, so that the whole conversation can be available. Every feedback submitted will be evaluated carefully by our engineers. They will let you know their comments further through that portal. It would be great if you can also paste the link to the submitted feedback here, so that other community members can see it as well.

Thanks.
Rong-Chun Zhang

Rong-Chun Zhang  Friday, April 11, 2008 2:55 AM

For further progress this feedback was forwarded to the Connect Portal.

a3ronco  Friday, April 11, 2008 9:26 AM

You can use google to search for other answers

Custom Search

More Threads

• MainMenu item and Controls.Remove()
• Can't hide base class properties
• IExtenderProvider: how to get a reference to the original extended controls
• listview over picturebox
• Read the data from Datagrid view
• Adding a control's context menu to the parent form's context menu
• Problem while closing the win form
• Controls get hidden in designer after debugging
• Get click event in empty panel.
• Using commands/verbs in the PropertyGrid when hosting the Form Designer