Visual C# Developer Center > Visual C# Forums > Visual C# IDE > Accessing Resources Fom Another Project Via The Properties Window
Ask a questionAsk a question
 

AnswerAccessing Resources Fom Another Project Via The Properties Window

  • Friday, October 30, 2009 3:14 PMHerr Blitzkrieg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Is there a way to access resources that are in a resource file in another project using the Properties window in the IDE?

    Background:
    Visual Studio Team System 2008
    Language: C#

    Two projects in the solution: application project, library with user controls and common resources.

    Say a new form is created in the application project. If I try to set the background image property from the properties window using an image in the common resources, there seems to be no way to specify that file as the source of the resources.

    Is such a thing possible?

Answers

All Replies

  • Friday, October 30, 2009 3:19 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    You wouldn't do that typically.  Using the properties/resources window you can set the accessibility modifier of your resources within your class library, but you have to do that from the class library itself.  There's a drop-down at the top of the page. After that, it's a simple matter of referencing it in code:

    ClassLibrary1.Properties.Resources.SomeImage

    In other words, when calling on the resource from the main application, you wouldn't use the resources of the main application, you would use the now public resources of the class library.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • Friday, October 30, 2009 4:12 PMHerr Blitzkrieg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Yes, in the class libary the resources are public and can be accessed from the code in either project by dereferencing the assembly just as you indicated. But I can't access the resources, specifically image resources, from Visual Studio Designer. It lets me import the image file into the control's local .resx file or it looks for a project local resource file. But I wish I could type into the image property field to dereference the resource but it won't let me do that either.

    I guess ultimately the designer is generating code so it doesn't really matter who (me or the IDE) does it. I think it's more intuitive to use the IDE since a lot of the UI designed using it and that's where most developers go first.

  • Friday, October 30, 2009 4:14 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Yeah, there's no way to do that from the IDE other than to manually edit the code.  Sorry.
    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
  • Friday, October 30, 2009 5:10 PMHerr Blitzkrieg Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks for the quick replies David - much appreciated.