Resource converted from Resource File to Local Resource

Ontani

Centurion
Joined
Mar 3, 2004
Messages
121
Location
Belgium
Hey,

I'm creating an class library in wich I have a resource file that contains an image that is going to be used as a backgroundImage of a custom control (Button).

So in the Sub New() of my custom Button I added:

Me.BackgroundImage = My.Resources.Resources.customImage

When I drag the control on a form in my class library the backgroundImage property doesn't hold a reference to the image in the resource file but instead created an local resource (formName.resx) and replaced the property with System.Drawing.Image.

Now when I change the property of the control manualy to use the Resources.resx file and the customImage element in that resource. For some reason everything seems to work like a charm.

Why on earth would visual studio change my code (where I refer to a resource file) to an local resource.

Offcourse this would make me completly lose the advantage of resource files because when changes are made to any of the images I would have to replace them in all the local resource files.

Anyone an idea what is going on or how I am able to prevent this from happening.

Thanks in advance
 
What about a resource manager, which shares its resources to the outer world?

Something like this: I used it for a outlook style control, which was created in a control library, but he needed resources from same library.
I couldn't access it by my.Resources since it was another assembly. Just add resources to the resource pane on the property pages of y7our project and then export it with a public class with shared properties

Code:
''' <summary>
''' Export resource images from this dll
''' </summary>
''' <remarks></remarks>
Public Class EccIconManager

#Region " - Outlook - "
    ''' <summary>
    ''' Arrow Down
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property ArrowDown() As Icon
        Get
            Return My.Resources.Arrow_Down
        End Get
    End Property

    ''' <summary>
    ''' Arrow Up
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property ArrowUp() As Icon
        Get
            Return My.Resources.Arrow_Up
        End Get
    End Property

    ''' <summary>
    ''' Default Icon
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Shared ReadOnly Property [Default]() As Icon
        Get
            Return My.Resources.DefaultIcon
        End Get
    End Property
#end region
end class

~DP
 
Anything I tried including your solution resulted the same: resource from resource file gets converted into a local resource
 
The problem is most likely the result of the way that Visual Studio serializes forms for the designer. When it sees that a control has an image property, it doesn't know where the image came from. Visual Studio assumes that the image has been set through the designer (as opposed to by the control with a preexisting resource), and unless the designer is instructed otherwise, it automatically stores a copy of the image in the form's local resource file.

What I've been doing to prevent this is shadow the BackgroundImage property with a dummy property to effectively hide it from the designer. If you do this, though, then you need to remember to access the actual background image via the MyBase keyword, and if the class is to be inherited then you would need to create a new property or new methods to access the image.
 
I'v tried every possible combination of the image properties and the resx properties. It looks like marble_eater might me the one with a possible workaround here.

Thanx
 
Back
Top