Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. From Form to DLL - How Do I Package Resource Icons and Files?

From Form to DLL - How Do I Package Resource Icons and Files?

Scheduled Pinned Locked Moved Windows Forms
tutorialquestionlearningcsharphardware
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tom911
    wrote on last edited by
    #1

    I began with a textbook Form example (Petzold's Directory TreeView Form)that uses icon resources and modified/experimented with it to begin the C# learning process. There are icon resource files used in the project and they have their property "Build Action" set to "Embedded Resource". My attempts at placing the icons in their own folder failed. It seems they must be in the solution's root directory? I suspect this observation is because: "I don't know diddly yet!" I am now trying to transform my modified Petzold code into a DLL. I need to learn how to wrap up the resources so that they are contained in the DLL. I've been able to create and use the DLL ... but only when I "copy" the icon resource files into the \bin\release directory. :( What are the steps I should take so that the resources become a part of the single *.dll file? When I double click the "Properties" folder in the SolutionExplorer and then select "Resources" ... I am prompted to create a default resources file. Here I can add Icon files and text files. Awesome if that was all that was needed to have the resources become part of the DLL file!! But my DLL does not "find" those resources. :(( Again, I seem to have to copy them into the \bin\release directory for them to be found. Please teach me or point me towards a good tutorial or textbook that covers the usage of resources in a DLL. Thanks for all help and suggestions. -- Tom

    A 1 Reply Last reply
    0
    • T Tom911

      I began with a textbook Form example (Petzold's Directory TreeView Form)that uses icon resources and modified/experimented with it to begin the C# learning process. There are icon resource files used in the project and they have their property "Build Action" set to "Embedded Resource". My attempts at placing the icons in their own folder failed. It seems they must be in the solution's root directory? I suspect this observation is because: "I don't know diddly yet!" I am now trying to transform my modified Petzold code into a DLL. I need to learn how to wrap up the resources so that they are contained in the DLL. I've been able to create and use the DLL ... but only when I "copy" the icon resource files into the \bin\release directory. :( What are the steps I should take so that the resources become a part of the single *.dll file? When I double click the "Properties" folder in the SolutionExplorer and then select "Resources" ... I am prompted to create a default resources file. Here I can add Icon files and text files. Awesome if that was all that was needed to have the resources become part of the DLL file!! But my DLL does not "find" those resources. :(( Again, I seem to have to copy them into the \bin\release directory for them to be found. Please teach me or point me towards a good tutorial or textbook that covers the usage of resources in a DLL. Thanks for all help and suggestions. -- Tom

      A Offline
      A Offline
      Aurelius1664
      wrote on last edited by
      #2

      If you add a resource file controled by .net you can access the images in code using the resource file name. For example if you add an image (MyImage.jpg) to a resource file (MyResources.resx) you will be able to access it like below (check your compiler warnings and click enable strongly typed resources if you see it). Image myImage = MyResource.MyImage; However, I suspect you may be having problems with the namespaces of your code. To access resources you must correctly know the namespace. You can embed resources just like you mentioned by changing the build options in properties. If you do this you would need to do the following to access the image. Note that the resource name includes the full namespace which will by default include any sub folders used to store the image. Assembly assemblyExecuting; Stream streamImage; Image imageMine assemblyExecuting = Assembly.GetExecutingAssembly(); streamImage = assemblyExecuting.GetManifestResourceStream("MyNameSpace.Folder.FileName.jpg"); imageMine = Image.FromStream(streamImage); streamImage.Close();

      http://www.effinities.com

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups