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. C#
  4. Using resources

Using resources

Scheduled Pinned Locked Moved C#
csharpgraphicsquestionlearning
3 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.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I have couple of bitmaps in the root of my project (as Embaded Resources). When I want to reference them I'm using a code like this: Bitmap bmp=new Bitmap(GetType(),"Bitmap1.bmp"); pictureBox1.Image=bmp; But I would like to organize my project and move all the bitmaps to the folder "Bitmaps". Now the first line of the code above will bomb saying that "The resource "Bitmap1.bmp cannot be found in the class SomeNameSpace.SomeClass", where SomeClass is a class where I reference the Bitmap1.bmp. How could I instruct C# to find my bitmap? Jerzy

    J 1 Reply Last reply
    0
    • L Lost User

      I have couple of bitmaps in the root of my project (as Embaded Resources). When I want to reference them I'm using a code like this: Bitmap bmp=new Bitmap(GetType(),"Bitmap1.bmp"); pictureBox1.Image=bmp; But I would like to organize my project and move all the bitmaps to the folder "Bitmaps". Now the first line of the code above will bomb saying that "The resource "Bitmap1.bmp cannot be found in the class SomeNameSpace.SomeClass", where SomeClass is a class where I reference the Bitmap1.bmp. How could I instruct C# to find my bitmap? Jerzy

      J Offline
      J Offline
      James T Johnson
      wrote on last edited by
      #2

      Does "Bitmaps.Bitmap1.bmp" work? I've never used the syntax you have here before, glad to see it doesn't always have to be as long as myAssembly.GetManifestStream yadda yadda yadda;. James Sonork ID: 100.11138 - Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

      L 1 Reply Last reply
      0
      • J James T Johnson

        Does "Bitmaps.Bitmap1.bmp" work? I've never used the syntax you have here before, glad to see it doesn't always have to be as long as myAssembly.GetManifestStream yadda yadda yadda;. James Sonork ID: 100.11138 - Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        No, it doesn't. What is required here is a namespace: This is an example from Mr. Petzold: Icon=new Icon(typeof(ProgramWithIcon),"ProgramWithIcon.ProgramWithIcon.ico"); The first argument of the constructor refers to ProgramWithIcon class. Within that type operator, you can use the name of any class that your program defines. Or you can use the name of any structure, enumeration, interface, or delegate that you program defines. In any code in the ProgramWithIcon class, the expression: typeof(ProgramWithIcon) is equivalent to: GetType() This equivalence means that you can use the somewhat shorter constructor: Icon=new Icon(GetType(),"ProgramWithIcon.ProgramWithIcon.ico"); And the program still works the same. The second argument to the Icon constructor is more or less a filename. If you named the icon MyIcon.ico, the Icon constructor would look like this: Icon=new Icon(GetType(),"ProgramWithIcon.MyIcon.ico"); The first part of the quoted name is called a namespace, but it’s a resource namespace. Don’t confuse it with the .NET Framework namespace. By default, Visual C# .NET gives this resource namespace the same name as the project, but you can change it. It’s the field labeled Default Namespace in the Property Pages dialog box for the project. The name in that field must agree with the first part of the quoted name in the Icon constructor. You can even set Default Namespace field to nothing, in which case the second argument to the Icon constructor is just the bare filename: Icon=new Icon(GetType(),"ProgramWithIcon.ico"); or MyIcon.ico or whatever you’ve named the file. If you’re running the C# compiler from the command line, you use the /res switch for each resource. For example, if you use the compiler switch: /res:ProgramWithIcon.ico you load the icon like so: Icon =new Icon(GeType(),”ProgramWithIcon.ico”); Or you can give the icon an extended name following the filename and a comma: /res:ProgramWithIcon.ico,ProgramWithIcon.ProgramWithIcon.ico You then use the constructor: Icon =new Icon(GeType(),”ProgramWithIcon. ProgramWithIcon.ico”); to load the icon. Here’s a problem you might run into if you just use the default resource namespace name that Visual C# .NET assigns to your project: Suppose you create a new project named ProgramWithIconPlus in which the ProgramWithIconPlus inherits from the ProgramWithIcon class. In the ProgramWithIconPlus project, you create a new file named ProgramWithIconPlus.cs and you also add a link to the existing ProgramW

        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