![](https://p-blog.csdn.net/images/p_blog_csdn_net/LiYang2087/logo.gif)
logo.gif
using
System;
using
System.Drawing;
using
System.Resources;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
class
resource
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
static void Main(string []args)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
ResourceWriter rw=new ResourceWriter("Demo.resources");
using(Image image=Image.FromFile("logo.gif"))
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.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;
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
static
class
Program
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
static void Main()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
public
class
Form1 : Form
![](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
...
{
public Form1()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
InitializeComponent();
Assembly assembly=Assembly.GetExecutingAssembly();
rm=new ResourceManager("Demo",assembly);
logo.Image=(Image)rm.GetObject("logo");
}
private void Form1_Load(object sender, EventArgs e)
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
private void InitializeComponent()
![](https://i-blog.csdnimg.cn/blog_migrate/37c8bf68cdc3cc81759c34160776bc53.gif)
...{
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();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
this.logo.Location = new System.Drawing.Point(87, 12);
this.logo.Name = "logo";
this.logo.Size = new System.Drawing.Size(200, 180);
this.logo.TabIndex = 0;
this.logo.TabStop = false;
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
this.Anthor.AutoSize = true;
this.Anthor.Location = new System.Drawing.Point(148, 252);
this.Anthor.Name = "Anthor";
this.Anthor.Size = new System.Drawing.Size(35, 13);
this.Anthor.TabIndex = 1;
this.Anthor.Text = "label1";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
this.Cource.AutoSize = true;
this.Cource.Location = new System.Drawing.Point(148, 205);
this.Cource.Name = "Cource";
this.Cource.Size = new System.Drawing.Size(35, 13);
this.Cource.TabIndex = 2;
this.Cource.Text = "label1";
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(393, 380);
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();
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
}
![](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
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
![](https://p-blog.csdn.net/images/p_blog_csdn_net/LiYang2087/untitl.JPG)