Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

 

''' <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

My Development System

Intel Core i7 920 @2.66Ghz

6 GB DDR3 SDRAM

Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot

GeForce GTX295 1.8 GB

3.5 TB HD

  • Leaders
Posted

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.

[sIGPIC]e[/sIGPIC]
Posted
How are the build action property and Copy to output directory properties of the image set and of the resx?

My Development System

Intel Core i7 920 @2.66Ghz

6 GB DDR3 SDRAM

Windows 7 Ultimate x64 & Windows Vista Home Premium x64 dual boot

GeForce GTX295 1.8 GB

3.5 TB HD

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...