Resource(资源)

来源:互联网 发布:悦木之源菌菇水 知乎 编辑:程序博客网 时间:2024/05/04 07:05

 

 

                                                             

                                                                             logo.gif

 

using System;
using System.Drawing;
using System.Resources;

class resource
{
   
static void Main(string []args)
   
{
       ResourceWriter rw
=new ResourceWriter("Demo.resources");
       
using(Image image=Image.FromFile("logo.gif"))
       
{
           rw.AddResource(
"logo",image);
           rw.AddResource(
"Title","C# Program");
           rw.AddResource(
"Author","Hello World!");
           rw.Close();
       }
   
   }

}

csc string.cs

运行string.exe

生成Demo.resouuces资源文件。

 

using System;
using System.Windows.Forms;
using System.Drawing;
using System.Reflection;
using System.Resources;

static class Program
{
    
static void Main()
    
{
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(
false);
        Application.Run(
new Form1());
    }

}


public class Form1 : Form
{
    
public Form1()
    
{
        InitializeComponent();
             
        Assembly assembly
=Assembly.GetExecutingAssembly();
        rm
=new ResourceManager("Demo",assembly);
            
        logo.Image
=(Image)rm.GetObject("logo");
           
    }

        
    
private void Form1_Load(object sender, EventArgs e)
    
{
    }


    
private void InitializeComponent()
    
{
        
this.logo = new System.Windows.Forms.PictureBox();
        
this.Anthor = new System.Windows.Forms.Label();
        
this.Cource = new System.Windows.Forms.Label();
        ((System.ComponentModel.ISupportInitialize)(
this.logo)).BeginInit();
        
this.SuspendLayout();

        
this.logo.Location = new System.Drawing.Point(8712);
        
this.logo.Name = "logo";
        
this.logo.Size = new System.Drawing.Size(200180);
        
this.logo.TabIndex = 0;
        
this.logo.TabStop = false;

        
this.Anthor.AutoSize = true;
        
this.Anthor.Location = new System.Drawing.Point(148252);
        
this.Anthor.Name = "Anthor";
        
this.Anthor.Size = new System.Drawing.Size(3513);
        
this.Anthor.TabIndex = 1;
        
this.Anthor.Text = "label1";

        
this.Cource.AutoSize = true;
        
this.Cource.Location = new System.Drawing.Point(148205);
        
this.Cource.Name = "Cource";
        
this.Cource.Size = new System.Drawing.Size(3513);
        
this.Cource.TabIndex = 2;
        
this.Cource.Text = "label1";

        
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        
this.ClientSize = new System.Drawing.Size(393380);
        
this.Controls.Add(this.Cource);
        
this.Controls.Add(this.Anthor);
        
this.Controls.Add(this.logo);
        
this.Name = "Form1";
        
this.Text = "Form1";
        
this.Load += new System.EventHandler(this.Form1_Load);
        ((System.ComponentModel.ISupportInitialize)(
this.logo)).EndInit();
        
this.ResumeLayout(false);
        
this.PerformLayout();

    }


    
private System.Resources.ResourceManager rm;
    
private System.Windows.Forms.PictureBox logo;
    
private System.Windows.Forms.Label Anthor;
    
private System.Windows.Forms.Label Cource;
}

 

csc /resource:demo.resources form.cs

运行form.exe

 

 

 

原创粉丝点击