Lesson 04.1: Creating the Location class

In this lesson, we will create a class to hold the Location information (including a graphic file to display).




To add an image to your project:

  • Create the image in your preferred graphics program.
  • Add the file to the project, as an existing item.
  • Set the images’ “Build Action” property to “Resource”
  • When displaying the file, you will need to include the assembly (project) name where the file is located, along with the path (folders) to the image file.
    • For this project, it will be “/Engine;component/Image/Locations/Home.png” (for the Home location image).


Image Files

All image files, in a zip file

Or, download the individual images (right-click, and save to your disk):

Source Code







Return to main page

24 thoughts on “Lesson 04.1: Creating the Location class

  1. Hi Scott,

    Just a comment – when adding the images and changing the Build Action from Content to Resource, you can select all the images in the Solution Explorer at once and change them all at once, rather than clicking each one and changing it individually.

    To select multiple items:
    1> click on the first one, and hold Shift down and click on the last one, to highlight all the items
    2> Also, individual items can be added or removed from the highlighted list by holding down Ctrl and clicking.
    3> Once the desired list of all items is selected, in the properties window, change Build Action just like you would for a single item, but it will change it for all highlighted items.

    I think this is good to point out because it can be applied to any objects in the solution that need to have their properties updated to the same thing.

    1. Yes. This is especially useful when working on Windows Forms programs, when you want to change some properties for many textboxes/labels/buttons. It makes setting height/width/alignment/etc. much faster than individually clicking on each one.

  2. Hi Scott,

    Thanks for these tutorials!

    Can you explain why the “;component” is needed after “/Engine” in the Image path?

    1. You’re welcome, Mike.

      If you want one project (WPFUI) to use a resource (image) from another project (Engine), you need to include “;component”. If the resource is in the same project/assembly, you do not need to include “;component”.

      There is some more information on this at: Microsoft documentation

  3. Hello Scott,

    Thanks for this awesome tutorial. When I tried to add the build option “Resource” on the images it wasn’t available. I found out that it was because it was in the Engine project. Once I moved it into the WPFUI project the buildAction option for “Resource” became available. I am guessing it has to do with the references or type of project my Engine project is. I noticed there were two types of class libraries to choose from in visual studio 2017 the .net framework version and the .net standard version. I choose the standard. If you know why the buildaction “resource” wasn’t available please let me know. I tried stackoverflow but came up with nothing


    1. Hello Emmanuel,

      I haven’t worked with .NET standard projects, but Microsoft has been trying to make .NET usable in different environments (Mac, Linux, etc.). However, some functions are not available in all environments – or, at least not available right now. This is especially true with .NET Core. There is some more information on this Stack Overflow question. Although, the answer might be more confusing than the question. I haven’t found anything that specifically shows why resource wouldn’t be allowed in a .NET Standard Class Library.

      In my copy of the solution, using Visual Studio Community 2017, the Engine project is a “Class Library (.NET Framework)” under Visual C# -> Windows Classic Desktop, and it allows adding an image as a resource.

  4. Hi Scott,

    Thank you for making these great tutorials, I am learning a lot about C# and able to learn how to make games from scratch which is great.
    I have a couple of questions I hope you don`t mind and Sorry if these questions has been asked before.

    I noticed in the last couple of lessons it says how many references there is above public/private etc, I was wondering how you set that up?

    I was also wondering if their is a simple way to add music/sound effects?

    And will you be adding more lessons to this tutorial like the JRPG graphics etc?

    Thanks again for these great tutorials,

    1. You’re welcome, Karl!

      For the references, that might be ReSharper (a Visual Studio plugin I use). It might also be part of Visual Studio. Visual Studio is always adding new features that are in ReSharper.

      You can add audio, but I have not done that in any programs (other than speech in a C# program like Jarvis).

      I do plan to add JRPG graphics. I haven’t added any new lessons in a few months. I started a new job, have been working on some side projects for clients, and am a little burnt out (sometimes I need a break).

  5. Hello! Thanks for the great article!

    For some reason I’m having trouble with the image paths. I’m using Visual Studio 2019 and for some reason the “/Engine;component/Image/Locations/Home.png” (or adjust for whichever filename we’re using) path doesn’t work for me. The only way I can get the image to appear is if I copy and paste the full path from File Explorer, starting with the drive and going all the way to the image. Is there an easier way to find the image path for the project? I’ve looked in the documentation but haven’t found it yet.

    1. You’re welcome!

      I haven’t installed Visual Studio 2019 yet, but will see if I can figure out what the problem is. For now, you can use the full file path. In a future lesson, we start moving the game data from resources to dynamically-loaded values from an XML file.

  6. Hi Scott, thanks a lot for the tutorials.

    Am having same issue with paths (Win 10, VS 2017 community)
    Am unable to add PNGs as resource, but using full path as suggested by V.H. works.

  7. Hi Scott, thank you for the tutorials!

    I have a little problem when I need to change Build Action on the images there is no resource option. Maybe you can help me.

        1. The problem is that the Engine project is a Class Library built with “.NET Standard”, and it needs to be a Class Library built with “.NET Framework”.

          There are two things you can do.
          1. Delete the solution, build a new one, and create the Engine project with .NET Framework.
          2. I found an older version of the solution that uses .NET Framework and copied it to https://www.dropbox.com/s/r4wj96pzxaq2l67/Rytis.zip?dl=0. However, that version is the code after lesson 04.3. So, you can read the next two lessons, but the changes are already made in those files.

          Let me know if you have any questions or problems.

  8. Hello I am having an issue with the home image not showing at all

    I even did copy and paste of your code to see if it was my coding and still no images (I made sure they were set to resource)

    1. Hi Jesse,

      The problem was that the Engine project was set to use “.NET Core 2.0”, and it needed to be “Class Library (.NET Framework)”. .NET Core does not have all the features of .NET Framework. I created an Engine project in .NET Framework, moved your files into it, and removed the original Engine project. You can download the updated solution files at: https://www.dropbox.com/sh/6uowj5rf9949ep0/AACYlgAU47boGdBdiK7bTu_aa?dl=0

      Visual Studio has several different versions of .NET (Framework, Core, Standard). You have to be careful when adding a project, because it’s easy to pick a different version – which might cause problems when you build you progrma.

      Let me know if you have any problems with the updated code, or any other questions.

      1. Thank you very much!

        I must of confused it thinking they may of made a new framework with legacy features built into it.

        It’s completely working now, images and all.

        As far as questions
        What is core for? it seems to have less features if I’m reading that right

        1. You’re welcome.

          .NET Core was built to work on Windows, Mac, and Linux computers – so people can create .NET Core programs that run on all of those operating systems. So, .NET Core only includes features that can work on all those operating systems, and it’s going to take a while until Microsoft adds all the features from .NET Framework into .NET Core.

          1. That makes sense. I hope it catches up. would be cool to have that kind of ability with multiple platforms.

            I guess I have plenty to learn even when I learn within a specific language haha.

Leave a Reply

Your email address will not be published. Required fields are marked *