Load Rescouce BMP image : Resource ResX « Development Class « C# / C Sharp






Load Rescouce BMP image

Load Rescouce BMP image
  
  using System;
  using System.Drawing;
  using System.Collections;
  using System.ComponentModel;
  using System.Windows.Forms;
  using System.Data;

  using System.Resources;

  public class MainForm : System.Windows.Forms.Form
  {
    private System.Windows.Forms.PictureBox pictureBox1;
    private System.Windows.Forms.Button btnLoadRes;
    private System.Windows.Forms.Label label1;
    private System.Windows.Forms.PictureBox pictureBox2;

    public MainForm()
    {
      InitializeComponent();
      CenterToScreen();
    }
    private void InitializeComponent()
    {
      System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
      this.pictureBox2 = new System.Windows.Forms.PictureBox();
      this.pictureBox1 = new System.Windows.Forms.PictureBox();
      this.btnLoadRes = new System.Windows.Forms.Button();
      this.label1 = new System.Windows.Forms.Label();
      this.SuspendLayout();
      // 
      // pictureBox2
      // 
      this.pictureBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
      this.pictureBox2.Location = new System.Drawing.Point(176, 72);
      this.pictureBox2.Name = "pictureBox2";
      this.pictureBox2.Size = new System.Drawing.Size(32, 32);
      this.pictureBox2.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBox2.TabIndex = 5;
      this.pictureBox2.TabStop = false;
      // 
      // pictureBox1
      // 
      this.pictureBox1.Image = ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
      this.pictureBox1.Location = new System.Drawing.Point(176, 16);
      this.pictureBox1.Name = "pictureBox1";
      this.pictureBox1.Size = new System.Drawing.Size(32, 32);
      this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
      this.pictureBox1.TabIndex = 1;
      this.pictureBox1.TabStop = false;
      // 
      // btnLoadRes
      // 
      this.btnLoadRes.Location = new System.Drawing.Point(8, 80);
      this.btnLoadRes.Name = "btnLoadRes";
      this.btnLoadRes.Size = new System.Drawing.Size(144, 23);
      this.btnLoadRes.TabIndex = 4;
      this.btnLoadRes.Text = "Load Happy dude!";
      this.btnLoadRes.Click += new System.EventHandler(this.btnLoadRes_Click);
      // 
      // label1
      // 
      this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold);
      this.label1.Location = new System.Drawing.Point(8, 16);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(152, 40);
      this.label1.TabIndex = 0;
      this.label1.Text = "Here is the image:";
      // 
      // MainForm
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
      this.ClientSize = new System.Drawing.Size(235, 128);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.pictureBox2,
                                      this.btnLoadRes,
                                      this.pictureBox1,
                                      this.label1});
      this.Name = "MainForm";
      this.Text = "Resource Loader";
      this.ResumeLayout(false);

    }
    static void Main() 
    {
      Application.Run(new MainForm());
    }

    private void btnLoadRes_Click(object sender, System.EventArgs e)
    {
      ResourceManager resources = new ResourceManager (typeof(MainForm));
      
      this.pictureBox2.Image = 
        ((System.Drawing.Bitmap)(resources.GetObject("pictureBox1.Image")));
      resources.ReleaseAllResources();  
    }
      
  }


           
         
    
  








Related examples in the same category

1.Create resource file and read value from it using IDictionaryEnumeratorCreate resource file and read value from it using IDictionaryEnumerator
2.Create resource file and read value from itCreate resource file and read value from it
3.Create File Based Resource Manager
4.ResX Resource WriterResX Resource Writer
5.Save Image file to resource fileSave Image file to resource file
6.Compile resource into the final exe fileCompile resource into the final exe file
7.Generate resource file with image
8.Save and load image from resource file
9.Save and read value from resx resource file
10.Writing a resource file programmatically
11.Reading resourcesReading resources
12.Resource file generator application for difference languages
13.Read Resource for difference langaugesRead Resource for difference langauges
14.Creating a new resource readerCreating a new resource reader
15.Get String Resource
16.Get Embedded Resource String
17.Get Resource As Bytes