using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Resources;

namespace ImageFromResource
{
    public partial class Form1 : Form
    {
        
      
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            LoadItem(button1.Text);
        }

        private void LoadItem(string resourceName)
        {
            try
            {
                ResourceManager rm = new ResourceManager(typeof(ImageResource));

                Bitmap objImage = (Bitmap)rm.GetObject(resourceName);

                if (objImage != null)
                {
                    pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
                    pictureBox1.Image = objImage;
                }
                else
                {
                    pictureBox1.SizeMode = PictureBoxSizeMode.Normal;
                    pictureBox1.Image = pictureBox1.ErrorImage;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void SelectItem(object sender, EventArgs e)
        {
            Button btnIndex = (Button)sender;
            LoadItem(btnIndex.Text);
        }

      
    }
}
