Resource file

0

Mam problem z wczytywaniem obrazków z pliku Resource1.resx który dodałem do projektu, mianowiecie jak próbuje przypisać picturebox sciezke do obrazka:

ResourceManager resources = new ResourceManager(typeof(Resource1));
            Bitmap b = (Bitmap)resources.GetObject("obrazek");
            pictureBox1.Image = b;

to wyskakuje błąd ze nie ma takiego pliku.
W czym jest problem?

0

sprobuj tego:

    public class ResourcesHelper
    {
        private static ResourcesHelper instance = null;

        public static ResourcesHelper Instance
        {
            get
            {
                if (instance == null)
                    instance = new ResourcesHelper();
                return instance;
            }
        }

        private ResourceManager rm = null;

        private ResourcesHelper()
        {
//SCIEZKA_DO_ZASOBOW - namespace resourca np Zasoby.Obrazki
            rm = new ResourceManager(SCIEZKA_DO_ZASOBOW, Assembly.GetExecutingAssembly());
        }

        public Image GetImg(string img)
        {
            return (Image)rm.GetObject(img);
        }
    }

uzywasz tego tak:

           Image img = ResourcesHelper.Instance.GetImg("obrazek");

pozdr.

1 użytkowników online, w tym zalogowanych: 0, gości: 1